开发者

Django. Empty_label custom value

开发者 https://www.devze.com 2023-04-03 11:24 出处:网络
I want to change the value of default empty_label of field. So I did something like this with my field in:

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

精彩评论

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