In UserAdmin, I will display only users with is_active = True
.
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
class ReplacedUserAdmin(UserAdmin):
list_display = (
'id',
'email',
'username',
'last_name',
'first_name',
'date_joined',
'is_staff',
'is_superuser',
)
ordering = ('-is_active', '-id',)
def get_queryset(self, request):
return super().get_queryset(request).filter(is_active=True)
# Replace UserAdmin.
admin.site.unregister(User)
admin.site.register(User, ReplacedUserAdmin)
When using the @admin.register
decorator, it doesn't work well due to the order of code evaluation.
Write these two lines together:
admin.site.unregister(User)
admin.site.register(User, ReplacedUserAdmin)
Comments