दस्तावेज़ों में एक उदाहरण के अलावा, मुझे कोई दस्तावेज नहीं मिल रहा है कि कैसे django नाम चुनता है जिसके साथ कोई मूल वस्तु से बच्चे ऑब्जेक्ट तक पहुंच सकता है। उनके उदाहरण में, वे निम्न कार्य करें:django एक-से-एक संबंध बच्चे के ऑब्जेक्ट को नाम कैसे चिह्नित करता है?
class Place(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)
def __unicode__(self):
return u"%s the place" % self.name
class Restaurant(models.Model):
place = models.OneToOneField(Place, primary_key=True)
serves_hot_dogs = models.BooleanField()
serves_pizza = models.BooleanField()
def __unicode__(self):
return u"%s the restaurant" % self.place.name
# Create a couple of Places.
>>> p1 = Place(name='Demon Dogs', address='944 W. Fullerton')
>>> p1.save()
>>> p2 = Place(name='Ace Hardware', address='1013 N. Ashland')
>>> p2.save()
# Create a Restaurant. Pass the ID of the "parent" object as this object's ID.
>>> r = Restaurant(place=p1, serves_hot_dogs=True, serves_pizza=False)
>>> r.save()
# A Restaurant can access its place.
>>> r.place
<Place: Demon Dogs the place>
# A Place can access its restaurant, if available.
>>> p1.restaurant
तो उनके उदाहरण में, वे बस p1.restaurant स्पष्ट रूप से उस नाम को परिभाषित करने के बिना कहते हैं। Django मानता है कि नाम लोअरकेस के साथ शुरू होता है। क्या होता है यदि ऑब्जेक्ट नाम में एक से अधिक शब्द हैं, जैसे FancyRestaurant?
साइड नोट: मैं इस तरह से उपयोगकर्ता ऑब्जेक्ट को विस्तारित करने का प्रयास कर रहा हूं। क्या यह समस्या हो सकती है?