这个:
class ArticleForm(Form):
title = forms.CharField(label="Title", max_length=255,required=True)
short = forms.CharField(label="Short Description",widget=Textarea(attrs={'rows':'4'}),required=True)
content = forms.CharField(label="Content",widget=Textarea(attrs={'rows':'20'}),required=True)
categories = forms.MultipleChoiceField(label="Audit Group",choices=[(o.id, o.real_name()) for o in AuditGroup.objects.all()], widget=forms.CheckboxSelectMultiple
)
被很好地呈现为一个视图 - 然后我意识到我需要一个ModelForm
!;)
但是这个:
class ArticleForm(ModelForm):
class Meta:
model = Article
fields = ("title","categories","topic","short_desc","content")
widgets = {
'short_desc':Textarea(attrs={"rows":'4'}) ,
'content':Textarea(attrs={"rows":'20'}) ,
'categories':CheckboxSelectMultiple(choices=[(o.id, o.real_name()) for o in AuditGroup.objects.all()]),
'topic':CheckboxSelectMultiple(choices=[(o.id, o.name) for o in Topic.objects.all()])
}
在我看来没有正确显示标签。这应该由o.real_name()
和o.name
函数来完成。
任何想法?谢谢!