Opened 4 years ago

Closed 4 years ago

#31756 closed Bug (duplicate)

Use get_list_filter on ModelAdmin.lookup_allowed

Reported by: Jakub Boukal Owned by: nobody
Component: contrib.admin Version: 3.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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

link

Change History (1)

comment:1 by Mariusz Felisiak, 4 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #22569.

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