[Django] #31756: Use get_list_filter on ModelAdmin.lookup_allowed

10 views
Skip to first unread message

Django

unread,
Jul 1, 2020, 5:18:18 AM7/1/20
to django-...@googlegroups.com
#31756: Use get_list_filter on ModelAdmin.lookup_allowed
-----------------------------------------+------------------------
Reporter: Jakub Boukal | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.0
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 |
-----------------------------------------+------------------------
Hi,

I have a model and admin panel like so


{{{
# models.py
class Foo(models.Model):
bar = models.CharField(max_length=50)
user = models.ForeignKey(User, on_delete=models.CASCADE)


# admin.py
@admin.register(models.Foo)
class FooAdmin(admin.ModelAdmin):
list_filter = ['bar']

def get_list_filter(self, request):
if request.user.is_superuser:
return self.list_filter + ['user__groups']
return self.list_filter
}}}

After creating {{{Foo}}} object and assigning user to group I've tried to
filter on user's groups but I get {{{HTTP:400
DisallowedModelAdminLookup}}}.

I believe this is because {{{BaseModelAdmin.lookup_allowed}}} checks if
the lookup exists in {{{self.list_filter}}} but doesn't call a hook
{{{self.get_list_filter}}}

[https://github.com/django/django/blob/3.1b1/django/contrib/admin/options.py#L415
link]

--
Ticket URL: <https://code.djangoproject.com/ticket/31756>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 1, 2020, 5:29:28 AM7/1/20
to django-...@googlegroups.com
#31756: Use get_list_filter on ModelAdmin.lookup_allowed
-------------------------------+--------------------------------------

Reporter: Jakub Boukal | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #22569.

--
Ticket URL: <https://code.djangoproject.com/ticket/31756#comment:1>

Reply all
Reply to author
Forward
0 new messages