Reputation: 23
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
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?
Upvotes: 2
Views: 5290
Reputation: 798456
u.interest = u','.join(self.cleaned_data['interest'])
Upvotes: 1