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 itssave
method that is described here in the docs and in this example - use this form in the
ModelAdmin
as shown here in the docs
- [Answer]-Django form, handle multiple entities creation
- [Answer]-Add css class from database to manytomany field
- [Answer]-Deny deletion of model if it is referenced in a ManyToMany Relationship
- [Answer]-Django functional testing with selenium database creation
- [Answer]-Django ORM spouse, children, parent relationships
Source:stackexchange.com