如何得到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'])

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM