Reverse Query Name Clash?
Hi,
I'm getting a error about reverse query name clashes with my models.
We have a Django app to manage conferences and conference attendees.
In our models.py, two of the models we have are:
1. Person, representing people attending people attending a
conference. Each person also has a "church" field, which represents
the main church they attend.
class Person(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
gender = models.CharField(max_length=1,
choices=GENDER_CHOICES)
spouse = models.ForeignKey('self', null=True, blank=True)
date_of_birth = models.DateField()
church = models.ForeignKey('Church')
...
The "church" FK is in quotation marks, since the Church object is
defined below Person.
2. "Church", which defines a church, and includes an optional field
for the main minister at that church. The minister field is a FK to a
Person.
class Church(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=50)
suburb = models.CharField(max_length=30)
postcode = models.IntegerField()
state = models.CharField(max_length=3, choices=AUSTRALIAN_STATES)
minister = models.ForeignKey(Person, null=True, blank=True)
So a person has a church, and a church also has a minister (in most
cases the two will be different, except for the case where the
minister themselves is attending a conference, which should of course
be valid).
The issue here is that the model doesn't validate:
Error: One or more models did not validate:
conferences.church: Reverse query name for field 'minister'
clashes with field 'Person.church'. Add a related_name argument to the
definition for 'minister'.
Now, if I change the name of the "church" field under Person, it will
validate - however, I'm still curious as to why this doesn't work? Any
way to fix it? (I assume I could add a related_name argument, I'm just
trying to figure out what's going on, and gain more understanding for
Django).
Cheers,
Victor
--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home