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
Post a Comment