相关疑难解决方法(0)

为Django表单选择小部件添加其他选项

我有一个表单,我用它来构建一个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)

django django-forms

19
推荐指数
1
解决办法
3万
查看次数

Django表单字段选择,添加属性

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)

如何实现?

django django-forms

16
推荐指数
4
解决办法
2万
查看次数

标签 统计

django ×2

django-forms ×2