Django admin interface: the "groups" page extension shows its users and allows you to add new users
In the default admin interface, the group page is not very complete. (attached to the picture) I do not see users who are part of this group and I cannot add users there (I need to go to the user profile and add them to the group one by one)
I tried to extend this functionality from admin.py
but not sure how. If auth_group
, auth_user
and auth_user_groups
were user-defined models in models.py
, I would probably do something like this:
from django.contrib import admin
from myproject.models import Group, User, GroupUserMembership
class MembershipInline(admin.TabularInline):
model = GroupUserMembership
extra = 1
class UserAdmin(admin.ModelAdmin):
inlines = (MembershipInline,)
class GroupAdmin(admin.ModelAdmin):
inlines = (MembershipInline,)
admin.site.register(Group, GroupAdmin)
admin.site.register(User, UserAdmin)
But this will lead to
Exception Value: The model Group is already registered
(also i don't know how to import auth_user_groups
)
TL; DR . How do I extend Django's admin interface to map a many-to-many relationship between the default auth models User
and Groups
? (for example, Permissions
in the picture below)
source to share