我有一个表单,我用它来构建一个queryeset过滤器.表单从数据库中提取项目状态选项.但是,我想添加其他选项,例如"所有实时促销"......所以选择框看起来像是这样的:
这里'*'是我想要添加的,其他来自数据库.
这可能吗?
class PromotionListFilterForm(forms.Form):
promotion_type = forms.ModelChoiceField(label="Promotion Type", queryset=models.PromotionType.objects.all(), widget=forms.Select(attrs={'class':'selector'}))
status = forms.ModelChoiceField(label="Status", queryset=models.WorkflowStatus.objects.all(), widget=forms.Select(attrs={'class':'selector'}))
...
retailer = forms.CharField(label="Retailer",widget=forms.TextInput(attrs={'class':'textbox'}))
Run Code Online (Sandbox Code Playgroud) PLANNING_CHOICES = (
('0',u'Every morning'),
('1',u'Every night'),
('2',u'Never'),
)
planning = forms.ChoiceField(
required=True,
choices = PLANNING_CHOICES,
)
Run Code Online (Sandbox Code Playgroud)
有一个名为planning的表单字段,我需要在选项中添加title属性,最后呈现为:
<select>
<option value="0" title="bla1">Every morning</option>
<option value="1" title="bla2">Every night</option>
<option value="2" title="bla3">Never</option>
</select>
Run Code Online (Sandbox Code Playgroud)
如何实现?