On Sun, 2007-03-11 at 04:46 +0000, Laurie wrote:
[...]
> I'm
> having some trouble using the relationship. Using the example models
> from the 'One-to-one relationships' page:
> 
> p = Place(name="p1",address="...")
> r = Restaurant(place=p,serves_hot_dogs=True,serves_pizza=True)r.place
> Traceback (most recent call last):
>   File "<console>", line 1, in ?
>   File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/site-packages/django/db/models/fields/related.py", line 165,
> in __get__
>     raise self.field.rel.to.DoesNotExist
> DoesNotExist
> r.nameTraceback (most recent call last):
>   File "<console>", line 1, in ?
> AttributeError: 'Restaurant' object has no attribute 'name'
> 
> It seems I can't access the 'parent type' instance/properties. If I
> insert
> a p.save() before constructing r, I can dereference p.place, but the
> Restaurant instance still doesn't have the fields from Place.

I think you are misunderstanding how OneToOne works: it is an explicit
join field between the tables, not an implicit (transparent) one. So in
order to access the fields of Place from a Restaurant class, you will
always need to use queries like

        r.place.name

and so on. OneToOneField is not model inheritance. It provides similar
functionality in terms of linking models together, but the access
pattern is a little more cumbersome, which is why we are also
implementing more transparent model inheritance.

> Is the model inheritance implementation far enough along I could
> grab it off a branch somewhere and fill in the

Not at the moment, no. Sorry. We're leading up to 0.96 at the moment and
I'm putting all my free time into that.

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to