form.py :
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']
现在,我怎样才能在我的模板中呈现为像value1这样的字符串,没有[u'']的value2,还是有更好的方法将值保存为字符串?
答案 0 :(得分:1)
u.interest = u','.join(self.cleaned_data['interest'])