0
當我創建CustomerForm(),其是EnhancedModelForm(的子類),改變(所需= TRUE)初始化與__init__()
形式時,考慮由默認清潔方法不採取由?爲什麼是這樣?爲什麼在子類型表單上的驗證會中斷?
class EnhancedModelForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(EnhancedModelForm, self).__init__(*args, **kwargs)
test = self.errors
和窗體
class CustomerForm(EnhancedModelForm):
class Meta:
model = Customer
fields = ('salutation', 'first_name', 'last_name', 'phone_number', 'email_address')
def __init__(self, *args, **kwargs):
super(CustomerForm, self).__init__(*args, **kwargs)
self.fields['phone_number'].required = True
self.fields['email_address'].required = True
這應該工作。你能展示一些代碼來證明這個問題嗎? – 2012-02-03 14:19:50
你是對的,我做了一些更多的測試,當我嘗試訪問self.errors驗證這些修改字段失敗(請參閱上面的示例) – 2012-02-03 16:23:50