﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7545	Can't create an abstract model with 2 foreign keys to the same model	djangoproject.com@…	nobody	"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'.
}}}
"		closed	Uncategorized	dev		invalid	abstract model inheritance		Unreviewed	0	0	0	0	0	0
