multiplechoicefield - How to save ModelMultipleChoiceField in Django view? -


i have subject model , customuser model. during registration users can select multiple subjects. following code in forms.

forms.py

class signupform(forms.form):     ...     subjects = forms.modelmultiplechoicefield(label="subjects",                                          widget=forms.checkboxselectmultiple,                                          queryset=subject.objects.all()) 

what can in views.py save data? usual method of cleaning data , using save method doesn't work unfortunately. scarily, similar questions have little no answers in so.

nevermind. found it.

if password == password2:                 u = customuser.objects.create_user(username, email, password, first_name=fname, last_name=lname, dob=year+'-'+month+'-'+day)                 u.subjects = subjects                 u.save 

i made mistake of trying squeeze in subjects in create_user method other variables.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -