#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.
--
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 on the web visit
https://groups.google.com/d/msgid/django-updates/049.e464818f646a6e6a140c1300139ed001%40djangoproject.com.