stworzyłem niestandardowy formularz z niestandardowych walidacji tak:Django jak zastąpić metodę clean() w podklasie niestandardowej postaci?
class MyCustomForm(forms.Form):
# ... form fields here
def clean(self):
cleaned_data = self.cleaned_data
# ... do some cross-fields validation here
return cleaned_data
Teraz, ta forma jest podklasy z innej formie, która posiada własną czystą metodę.
Jaki jest prawidłowy sposób wyzwalania obu metod clean()?
W tej chwili jest to, co robię:
class SubClassForm(MyCustomForm):
# ... additional form fields here
def clean(self):
cleaned_data = self.cleaned_data
# ... do some cross-fields validation for the subclass here
# Then call the clean() method of the super class
super(SubClassForm, self).clean()
# Finally, return the cleaned_data
return cleaned_data
wydaje się działać. Jednak powoduje to, że dwie metody clean() zwracają cleaned_data
, co wydaje mi się nieco dziwne.
Czy to jest właściwy sposób?
Robisz go poprawnie. –