[Answer]-How to modify group creation form in admin page

1👍

You can do it like this:

from django.contrib.auth.admin import GroupAdmin
from django.contrib.auth.models import Group

Membership = Group.user_set.related.through

class MembershipInline(admin.TabularInline):
    model = Membership
    extra = 1

GroupAdmin.inlines = list(GroupAdmin.inlines) + [MembershipInline]

A slighter cleaner way would be to create your own GroupAdmin, and use admin.site.unregister and admin.site.register, rather than monkey patching as above.

Also, note that the interface is rather crude, compared to the nice many-to-many widget that Django provides, but it works.

0👍

You add model fields to your ModelAdmin which will have no effect. What you should do instead is:

  • add the model fields to a Model somewhere
  • create a ModelForm that contains all the fields you need and customize its save method that is described here in the docs and in this example
  • use this form in the ModelAdmin as shown here in the docs

Leave a comment