如何得到django中form表单里的复选框(多选框)的值( MultipleChoiceField )

直接写代码吧

CHECKBOX_CHOICES = (
('Value1','Value1'),
('Value2','Value2'),
) class EditProfileForm(ModelForm):
interest = forms.MultipleChoiceField(required=False,
widget=CheckboxSelectMultiple(),
choices=CHECKBOX_CHOICES,) def save(self, *args, **kwargs):
u = self.instance.user
u.interest = self.cleaned_data['interest']
u.save()
profile = super(EditProfileForm, self).save(*args,**kwargs)
return profile

怎样得到如下数据呢

[u'value1', u'value2']

实现

u.interest = u','.join(self.cleaned_data['interest'])
上一篇:更改mysql数据库latin1_swedish_ci为utf8


下一篇:Python学习札记(三十二) 面向对象编程 Object Oriented Program 3