#7545 closed (invalid)
Can't create an abstract model with 2 foreign keys to the same model
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Uncategorized | Version: | dev |
Severity: | Keywords: | abstract model inheritance | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I am using newforms-admin revision 7770.
If you create an abstract model with 2 foreign keys (or generic relationships) to the same model and then inherit from the abstract model more than once you end up with "clashes with related field" errors.
Here is an example models.py:
from django.db import models class Foo(models.Model): title = models.CharField(max_length=200) class MyAbstraction(models.Model): """ If 'related_name' is removed from 'foo' and 'bar' is removed altogether, then everything works as expected. """ foo = models.ForeignKey('Foo', related_name='plop') bar = models.ForeignKey('Foo') class Meta: abstract = True class Extended(MyAbstraction): bax = models.CharField(max_length=200) class AnotherExtended(MyAbstraction): baz = models.CharField(max_length=200)
And it'll spit out these errors:
Error: One or more models did not validate: myproject.extended: Accessor for field 'foo' clashes with related field 'Foo.plop'. Add a related_name argument to the definition for 'foo'. myproject.extended: Reverse query name for field 'foo' clashes with related field 'Foo.plop'. Add a related_name argument to the definition for 'foo'. myproject.anotherextended: Accessor for field 'foo' clashes with related field 'Foo.plop'. Add a related_name argument to the definition for 'foo'. myproject.anotherextended: Reverse query name for field 'foo' clashes with related field 'Foo.plop'. Add a related_name argument to the definition for 'foo'.
Change History (2)
comment:1 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Version: | newforms-admin → SVN |
comment:2 by , 16 years ago
In the new documentation:
http://docs.djangoproject.com/en/dev/topics/db/models/#abstract-base-classes
Portfolio: http://www.xaba.nl/content/portfolio
CV: http://www.linkedin.com/in/klaasvanschelven
Note:
See TracTickets
for help on using tickets.
See http://www.djangoproject.com/documentation/model-api/#be-careful-with-related-name