2đź‘Ť
Was responding to Alasdair’s comment and got to playing with our admin code, and I was able to narrow it down to the method call that was causing the error.
We have a Lead
model that relates to our Company
model via a ManyToManyField (i.e. one lead can be for one or more companies). The field that relates Lead
to Company
has a related_name
of “leads”.
class Company(models.Model):
...
class Lead(models.Model):
companies = models.ManyToManyField(Company, blank=True, related_name='leads')
...
The CompanyAdmin
, looks like the following:
class CompanyAdmin(admin.ModelAdmin):
...
readonly_fields = 'leads',
...
def leads(self, obj):
...
So what appears to have been happening was, when we were trying to access the leads
method from CompanyAdmin
, Django was instead trying to access the company’s Lead
objects via the related name — the ManyToManyField that was throwing the error. I resolved the conflict by changing the method name in the admin to “my_leads”.
Looks like something was changed somewhere between 1.8 and the final version of 1.6 that has opened the door to potential conflict between related names and admin methods. The solution, make sure there is no overlap in naming, and things should work fine.