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.cleane开发者_如何学编程d_data['interest']
u.save()
profile = super(EditProfileForm, self).save(*args,**kwargs)
return profile
it saves in db as [u'value1', u'value2']
Now, How can I only render in my template to show as string like value1, value2 without [u' '] or is there a better way to save the value as a string?
u.interest = u','.join(self.cleaned_data['interest'])
精彩评论