
即使没有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)
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)