#36126: DisallowedModelAdminLookup on simple filters of FK fields with inheritance
child model as target
-------------------------------+-----------------------------------------
Reporter: Omar BENHAMID | Type: Bug
Status: new | Component: contrib.admin
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------
To reproduce :
1. Have an FK to a model which inherits another in models.py :
{{{
class Parent(Model):
#...
pass
class Child(Parent):
#...
pass
class FooBar(Model):
child = ForeignKey(Child, on_delete=models.CASCADE)
}}}
2. Have a simple list filter on that fk admin.py:
{{{
class FooBarModelAdmin(ModelAdmin):
model = FooBar
list_filter = ("child",)
}}}
3. Go to the admin of FooBar and try to filter by "child" you get :
{{{
django.contrib.admin.exceptions.DisallowedModelAdminLookup: Filtering by
child__parent_ptr__exact not allowed
}}}
**Workaround:** override {{{lookup_allowed(...)}}} in the
FooBarModelAdmin to allow lookup on {{{child__parent_ptr__exact}}}.
I think that the better fix would be to filter by child_exact rather than
{{{child__parent_ptr__exact}}}to avoid exposing some "unnecessary"
technical detail, but maybe it has side effects, so the default
{{{lookup_allowed(...)}}} should at least allow it.
--
Ticket URL: <
https://code.djangoproject.com/ticket/36126>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.