Opened 7 years ago

Last modified 7 years ago

#28262 closed Bug

Using lookup with autocreated fields crashes django admin — at Initial Version

Reported by: Michal Dabski Owned by: nobody
Component: contrib.admin Version: 1.11
Severity: Release blocker Keywords: admin, lookup_allowed
Cc: commonzenpython@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Consider the following models:

class AuditSession(Model):
    auditor = models.ForeignKey(User)

class Institution(BaseModel):
    name = models.CharField(max_length=100)

class Auditor(BaseModel):
    user = models.OneToOneField(User)
    institution = models.ForeignKey(Institution, null=True, blank=True)

And the following filter in audit session admin:

class AuditSessionAdmin(ModelAdmin):
    list_filter = (
        ('auditor__auditor__institution'),
    )

As of Django version 1.9 up to the latest release 1.11.1, the above lookup will raise server error when used by raising DisallowedModelAdminLookup (Filtering by auditorauditorinstitutionidexact not allowed). This is because the lookup uses reverse relation between User and Auditor model.

This lookup passes checks and only crashes when user tries to use the filter. I could not find the reasoning behind the implementation of lookup_allowed and why it would forbid using reverse relations. Nor could I find any documentation for this change in 1.9 release notes.
I have recently upgraded from django 1.8 where this lookup worked perfectly fine.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top