Hello Djangousers,

I'm quite young with Django, so I apologize for my question.


I just tried to do exactly what is written on OneToOneField (http://
www.djangoproject.com/documentation/models/one_to_one/) and
ModelInheritance (http://code.djangoproject.com/wiki/
ModelInheritance).

What I want is to retrieve a Restaurant from its Place.



On "On-to-one relationships", it is written :

# A Restaurant can access its place.
>>> r.place
<Place: Demon Dogs the place>

This obvisouly works, but :

# A Place can access its restaurant, if available.
>>> p1.restaurant
<Restaurant: Demon Dogs the restaurant>

Does not work at all, I only get :

AttributeError : 'Place' object has no attribute 'restaurant'

I don't know where the "restaurant" attribute is defined, and it seems
in the example that it's nowhere !



On "ModelInheritance", it is written (under the Part 3 : API) :

E.      Restaurant.objects.get(2).description   'Yuck!'

That obviously works too, but :

D.      Place.objects.get(2).description        'Yuck!' or AttributeError?

I do not get "Yuck!", I indeed get the "AttributeError :  'Place'
object has no attribute 'description'"

The problem is the same : where is it defined that a "Place" object
can access a "description" attribute ?



That's absolutely all i need to know for my own project.
Currently, I have tried the following workaround :

for place in Place.objects.select_related() :
    for restaurant in place.restaurants.all() :

And this works, as in "models.py", I have written :

Restaurant(models.Model) :
    place = models.ForeignKey(Place, db_column='place_id',
related_name='restaurants')

My workaround works, but needs around 2000 database connexions, where
a single "LEFT JOIN" SQL request is enough.


What I want is :

for place in Place.objects.select_related() :
    restaurant = place.restaurant

And I need your help to succeed.
I think it is possible and I'm just too young with Django.
If it is possible by "OneToOneField" AND "ModelInheritance", what is
the best way ?



Thank you for reading, and thank you again if, by any way, you can
help me.
Anthony.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to