It seems that Django has some serious restrictions/bug when there are two foreign keys pointing to the same Model and one of them has the edit_inline attribute set.
Suppose the following problem: a need to represent the concept of a callgroup: a list of items (either persons or, again, callgroups) to which phone calls should be dispatched in a given sequence. The model is illustrated at the end of this ticket.
When I try to use the Admin interface it seems to get
confused:
- If I set editable=False in callgroup_owner the Admin interface gets confused because there are two foreign keys from CallgroupItem to Callgroup: callgroup_owner and callgroup_member. In fact the Admin interface shows a TABULAR list of Callgroup items and, also, a STACKED list (however, only one should be shown).
I'm using version 0.96-pre of Django. Following is the data model I used (models.py) to isolate and reproduce the bug:
class Person (models.Model):
name = models.CharField(maxlength=15)
class Callgroup (models.Model):
name = models.CharField(maxlength=15)
class Admin:
pass
class CallgroupItem (models.Model):
sequence = models.IntegerField(core=True)
# Owner of this callgroup item
callgroup_owner = models.ForeignKey(Callgroup,
related_name="callgroup_owner",
editable=False, # Error even if True
edit_inline=models.TABULAR,
)
# Callgroup to be called (if not NULL)
callgroup_member = models.ForeignKey(Callgroup,
related_name="callgroup_member",
null=True, blank=True,
)
# Person to be called (if not NULL)
person_member = models.ForeignKey(Person,
related_name="person_member",
null=True, blank=True
)