Hi Benjamin,
you can create explicit OneToOne field with parent_link=True
https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.OneToOneField.parent_link

Then you can set different related_name for each model.


Cheers,
  Tom


Dne Wed, 12 Jun 2013 01:10:40 -0700 (PDT)
Benjamin  Wohlwend <piquad...@gmail.com> napsal(a):

> Hi,
> 
> I have a bit of a problem with inherited reverse relations and django model 
> inheritance. Consider these models:
> 
> 
> class Content(models.Model):
>     display = models.BooleanField()
> 
> 
> class Link(Content):
>     url = models.URLField()
> 
> 
> class Teaser(Content):
>     text = models.TextField()
>     link = models.URLField()
> 
> 
> As we all know, Django uses an implicit OneToOneField for model 
> inheritance. This OneToOneField generates accessors for the reverse 
> relation, which in this case means that objects of the type Content will 
> have a "link" and a "teaser" attribute to access the other side of the 
> one-to-one relation. These attributes are, of course, inherited to the 
> Content subclasses, meaning that Link and Teaser also will have those 
> accessors. But wait, Teaser already defines a link attribute! We got 
> ourselves a nice little name clash.
> 
> While it's perfectly according to the rules of inheritance for Link and 
> Teaser to inherit the "link" and "teaser" reverse relations accessors, it 
> is also a bit nonsensical in this case. As far as I can tell, it's not 
> possible to suppress the creation of these accessors when defining the 
> model inheritance. Any ideas how to get around this (other than "just 
> rename the link attribute in Teaser, silly!")?
> 
> Benjamin
> 
> P.S.: the real use case here is django CMS, with its content plugins all 
> inheriting from a CMSPlugin base class. Since there are e.g. subclasses 
> called Text, Link, and Picture, it's not possible to use field names called 
> "text", "link", or "picture" in a CMSPlugin subclass, which is frustrating 
> and hard to explain to our users.
> 



S pozdravem
  Tomáš Ehrlich

Email:  tomas.ehrl...@gmail.com
Tel:    +420 608 219 889
Jabber: elv...@jabber.cz

"Půjdu kamkoliv, pokud je to kupředu." - J. London

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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