On Fri, 2007-05-11 at 04:57 -0700, [EMAIL PROTECTED] wrote: > 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'
Did you create the models exactly as specified at the top of those tests (including populating the p1 and p2 objects as specified)? That particular file of tests is run automatically as part of our unittest suite and a few of use are running those tests many times a day. Currently there are no failures, so that code should work. It sounds like you are doing something different from what the test says here. > > I don't know where the "restaurant" attribute is defined, and it seems > in the example that it's nowhere ! One good feature about Django's relationships between models is that you don't need to annotate both ends of the link. Since the Restaurant model already says it links to the Place model, Django knows that Place therefore also links back to Restaurant. As to why that reverse-link attribute is called restaurant, that is the lower-cased version of the other model's name and is used automatically as the attribute name. > On "ModelInheritance", it is written (under the Part 3 : API) : Stop right there. The model inheritance code isn't implemented yet. So nothing on that page is expected to work. It will be implemented "soon". Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---