如何摆脱由Django Form的RadioSelect生成的虚假选择

如何摆脱由Django Form的RadioSelect生成的虚假选择,第1张

如何摆脱由Django Form的RadioSelect生成虚假选择

即使没有blank = True,它也会显示额外的输入。我创建了一个新的小部件

from itertools import chainfrom django.forms import RadioSelectfrom django.utils.encoding import force_unipreclass RadioSelectNotNull(RadioSelect):    def get_renderer(self, name, value, attrs=None, choices=()):        """Returns an instance of the renderer."""        if value is None: value = ''        str_value = force_unipre(value) # Normalize to string.        final_attrs = self.build_attrs(attrs)        choices = list(chain(self.choices, choices))        if choices[0][0] == '': choices.pop(0)        return self.renderer(name, str_value, final_attrs, choices)


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5649133.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存