Thanks, but I've omitted related_name and I've used distinct related_names and 
gotten the same errors. I don't want to reuse addresses. The one-to-one 
relationship you describe is precisely what I'm trying to do.

On Feb 14, 2013, at 1:32 AM, Jani Tiainen <[email protected]> wrote:

> Hi,
> 
> You're trying to setup one-to-one relationship.
> 
> It means that producer.mailing_address does have exactly one unique Address 
> entity. Same goes for physical_address.
> 
> What you want is really ForeignKey to address which means that you reuse 
> addresses to multiple producer.mailing_address.
> 
> Then you can omit related names, or like someone suggested use different 
> related names for both fields.
> 
> 13.2.2013 21:25, Ray Hatfield kirjoitti:
>> Hi,
>> 
>> I have a model which requires two addresses: a mailing address and a
>> physical address. From an OO perspective it makes sense to have an
>> Address class and the Producer to have Address instances as properties,
>> but I can't seem to achieve this in django while still being able to
>> edit the addresses inline as part of the Producer admin.
>> 
>> I've tried this sort of thing:
>> 
>> class Address( models.Model ):
>>     street = models.CharField( ... )
>>     # city state zip, etc.
>> 
>> class Producer( models.Model ):
>>     mailing_address = models.OneToOneField( Address, related_name='+' )
>>     physical_address = models.OneToOneField( Address, related_name='+' )
>> 
>> but when I attempt to inline the addresses in the django admin I run
>> into trouble. I get errors like:
>> 
>> <class 'producers.models.Address'> has no ForeignKey to <class
>> 'producers.models.Producer'>
>> 
>> (This error is true, of course. But I was under the apparently erroneous
>> impression that including related_name='+' would prevent django from
>> setting up the reverse relationship.)
>> 
>> I realize I could add a foreign key to Address to associate it with a
>> specific Producer but this feels backwards to me. An Address shouldn't
>> need to know whether it's for a Producer or some other object. It's just
>> an address.
>> 
>> I've been banging my head on this for far too long. Advice?
>> 
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send
>> an email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>> 
>> 
> 
> 
> -- 
> Jani Tiainen
> 
> - Well planned is half done and a half done has been sufficient before...
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to