我今天把这件事搞得一团糟,就想出了一个
胆小鬼
俏皮的解决方案:
# Cowardly handle ModelChoiceField empty label
# we all hate that '-----' thing
class ModelChoiceField_init_hack(object):
@property
def empty_label(self):
return self._empty_label
@empty_label.setter
def empty_label(self, value):
self._empty_label = value
if value and value.startswith('-'):
self._empty_label = 'Select an option'
ModelChoiceField.__bases__ += (ModelChoiceField_init_hack,)
现在您可以调整默认值
ModelChoiceField
任何你想要的东西都要空标签。-)
附言:不需要投反对票,无害的猴子补丁总是很方便的。