I would like to change admin for a group, so it would display how many users are there in a certain group. I'd like to display this in the view showing all groups, the one before you enter admin for certain group. Is it possible? I am talking both about how to change admin for a group and how to add function to list_display
.
staff. - A user marked as staff can access the Django admin. But permissions to create, read, update and delete data in the Django admin must be given explicitly to a user. By default, a superuser is marked as staff.
Groups are a means of categorizing users. This allows for granting permissions to a specific group.
To display both the three columns in the admin site model list page, you need edit the Django app's admin.py file ( dept_emp / admin.py ), then define a class which extends django. contrib. admin. ModelAdmin class.
First you'd need to import and subclass GroupAdmin
from django.contrib.auth.admin
. In your subclass, define a user_count
method. Then, unregister the existing Group model from the admin, and re-register the new one.
from django.contrib.auth.admin import GroupAdmin
from django.contrib.auth.models import Group
class GroupAdminWithCount(GroupAdmin):
def user_count(self, obj):
return obj.user_set.count()
list_display = GroupAdmin.list_display + ('user_count',)
admin.site.unregister(Group)
admin.site.register(Group, GroupAdminWithCount)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With