mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
Fixed #17646 -- Added a get_list_filter() method to ModelAdmin. Thanks to rasca for the suggestion and to mateusgondim for the patch.
This commit is contained in:
@@ -32,6 +32,7 @@ class ParentAdmin(admin.ModelAdmin):
|
||||
class ChildAdmin(admin.ModelAdmin):
|
||||
list_display = ['name', 'parent']
|
||||
list_per_page = 10
|
||||
list_filter = ['parent', 'age']
|
||||
|
||||
def queryset(self, request):
|
||||
return super(ChildAdmin, self).queryset(request).select_related("parent__name")
|
||||
@@ -90,3 +91,14 @@ class SwallowAdmin(admin.ModelAdmin):
|
||||
list_display = ('origin', 'load', 'speed')
|
||||
|
||||
site.register(Swallow, SwallowAdmin)
|
||||
|
||||
class DynamicListFilterChildAdmin(admin.ModelAdmin):
|
||||
list_filter = ('parent', 'name', 'age')
|
||||
|
||||
def get_list_filter(self, request):
|
||||
my_list_filter = super(DynamicListFilterChildAdmin, self).get_list_filter(request)
|
||||
if request.user.username == 'noparents':
|
||||
my_list_filter = list(my_list_filter)
|
||||
my_list_filter.remove('parent')
|
||||
return my_list_filter
|
||||
|
||||
|
||||
Reference in New Issue
Block a user