假设我必须覆盖ModelForm
(in forms.py
) 以设置labels
或widgets
不同。IE:
class SomeForm(ModelForm):
def __init__(self,*args,**kwargs):
super(someForm, self).__init__(*args, **kwargs)
self.fields['someVal'].label = ...
self.fields['someVal'].widget = ...
那我该如何设置required=True
呢?
我知道我可以在这样之前做到这__init__
一点:
class SomeForm(ModelForm):
someVal = CharField(required=True) # << here
def __init__(self,*args,**kwargs):
super(someForm, self).__init__(*args, **kwargs)
self.fields['someVal'].label = ...
self.fields['someVal'].widget = ...
但我正在做一些动态的东西,我想在__init__