开发者

Django. Empty_label custom value

I want to change the value of default empty_label of field. So I did something like this with my field in:

class RFXDigestModelForm(ModelForm):
    Time_frame_is_开发者_Python百科realistic = ModelChoiceField(
        queryset=models.RFXDigest.objects.all(),
        empty_label="(Nothing)",
        )

    class Meta:
        model = models.RFXDigest
        widgets = {
            'Time_frame_is_realistic': rfx_widgets.jQueryRadioSelect(),
        }

In result I have my own label for empty_label. But there is an issue: my widget doesn't appear on the page, instead django comboBox appear. How could i fix this? And can I somehow pass choice list to queryset parameter of ModelChoiceField?


Don't use the widgets dictionary if you're manually defining the field - put it in the field declaration.

Time_frame_is_realistic = ModelChoiceField(queryset=models.RFXDigest.objects.all(),
                                           empty_label="(Nothing)",
                                           widget=rfx_widgets.jQueryRadioSelect())

I don't understand your second question. If you want a custom choice list, use a normal ChoiceField rather than a ModelChoiceField.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜