Задать вопрос

Тел: +7 965 3737 888





Edit users on Group admin

Ordinarily, it is not possible to edit Group membership from the Group admin because the m2m relationship is defined on User. With a custom form, it is possible to add a ModelMultipleChoiceField for this purpose. The trick is to populate the initial value for the form field and save the form data properly.

One of the gotchas I found was that the admin framework saves ModelForms with commit=False and uses the save_m2m method when the group is finally saved. In order to preserve this functionality, I wrap the save_m2m method when commit=False.

Вопрос полезен? Да0/Нет0

Ответы (1):

Ответ полезен? Да0/Нет0

I believe there are a couple typos:

  1. AGLUser -> User and User would have to be imported. So add: from django.contrib.auth.models import User
  2. GroupChangeForm -> GroupAdminForm

Once you make these changes the form works great.