W
W
Wizzy2014-03-15 13:19:34
Django
Wizzy, 2014-03-15 13:19:34

Django. How to save multiselect fields?

I'm trying to add users to groups (default classes User and Group) without using admin.py
I create a form:

class EditForm(forms.ModelForm):
  class Meta:
    model = User
    fields = ['groups']

the form is displayed like this:
1.PNG
and after selecting groups, for some reason this field is not saved.
In fact, instead of the groups field, there are many more fields and all of them are saved, except for this multiselect. Can
you please tell me? How to save multiselect fields?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey K, 2014-03-16
@Wizzy

Made an example on editing users.
Combining functions for registration and editing is a very bad idea.
https://github.com/onrik/users_example
I hope everything is clear, there was no time to make beautiful html design.

A
Andrey K, 2014-03-15
@mututunus

Use form.save_m2m()
https://docs.djangoproject.com/en/1.6/topics/forms...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question