#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019492ce235f-35fa05c1-46be-4284-87ef-515290d44c3f-000000%40eu-central-1.amazonses.com.

Reply via email to