Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5954565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:59:21+00:00 2026-05-22T17:59:21+00:00

In the default Django admin view for user-object (edit user) one can edit the

  • 0

In the default Django admin view for user-object (edit user) one can edit the user’s group memberships. What if I wanted this the other way around also? I.e. in the group editing page one could select the users that belong to the group being edited.

As I see this, Django doesn’t have a ManyToMany mapping from Group to User object which makes it impossible(?) to implement a ModelAdmin class for this particular case. If I could make an additional UsersOfGroup model class and use it in the Django’s Group model’s ManyToMany field as a through-attribute, there could be a way.

Any ideas, is this possible to implement using ModelAdmin tricks or do I just have to make a custom view for editing groups?

I have checked these two other questions, but they don’t quite do the same thing:

Assigning a group while adding user in admin

and

Show group membership in admin

Updated:
The answer from Chris was almost there. 🙂 The group has a reference to the users set, but it’s called user_set, not users. So these are the changes I made:

if self.instance and self.instance.pk:
    self.fields['users'].initial = self.instance.user_set.all()

and

if group.pk:
    group.user_set = self.cleaned_data['users']
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:59:21+00:00Added an answer on May 22, 2026 at 5:59 pm

    yourapp/admin.py

    from django import forms
    from django.contrib import admin
    from django.utils.translation import ugettext_lazy as _
    from django.contrib.admin.widgets import FilteredSelectMultiple
    
    from django.contrib.auth.models import User, Group
    
    class GroupAdminForm(forms.ModelForm):
        users = forms.ModelMultipleChoiceField(
            queryset=User.objects.all(), 
            required=False,
            widget=FilteredSelectMultiple(
                verbose_name=_('Users'),
                is_stacked=False
            )
        )
    
        class Meta:
            model = Group
    
        def __init__(self, *args, **kwargs):
            super(GroupAdminForm, self).__init__(*args, **kwargs)
    
            if self.instance and self.instance.pk:
                self.fields['users'].initial = self.instance.users.all()
    
        def save(self, commit=True):
            group = super(GroupAdminForm, self).save(commit=False)
    
            if commit:
                group.save()
    
            if group.pk:
                group.users = self.cleaned_data['users']
                self.save_m2m()
    
            return group
    
    class GroupAdmin(admin.ModelAdmin):
        form = GroupAdminForm
    
    admin.site.unregister(Group)
    admin.site.register(Group, GroupAdmin)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is a followup question to Remove default apps from Django-admin I am trying
By default, in Django-admin there is Users, Groups, and Sites apps. How can I
How can I change the default widget for DateField instances in Django ADMIN? I
I am curious about the security of default admin panel of Django. For a
django.utils.translation.get_language() returns default locale if translation is not activated. Is there a way to
I have the following stack trace when trying to access the django admin default
I am using Django generic View but when i type /book/edit/9/ Then it says
How can I remove or change the verbose name of the default admin action
Whenever you run the command django-admin.py startproject , django automatically loads up a default
How do you increase the inactivity timeout for Django's admin? The default seems incredibly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.