Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Django admin, how to filter users by group?

It gives you filter by staff status and superuser status, but what about groups?

like image 215
rick Avatar asked May 19 '09 02:05

rick


1 Answers

Since version 1.3 it can be done using this:

list_filter = ('groups__name')

Of course as @S.Lott explains you must register your customized class in the admin.py file:

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

class MyUserAdmin(UserAdmin):
    list_filter = UserAdmin.list_filter + ('groups__name',)

admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)
like image 137
Francisco Puga Avatar answered Oct 05 '22 13:10

Francisco Puga