次のようなカスタム検証を使用してカスタム フォームを作成しました。
class MyCustomForm(forms.Form):
# ... form fields here
def clean(self):
cleaned_data = self.cleaned_data
# ... do some cross-fields validation here
return cleaned_data
現在、このフォームは、独自の clean メソッドを持つ別のフォームでサブクラス化されています。
両方の clean() メソッドをトリガーする正しい方法は何ですか?
現時点では、これは私がしていることです:
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
うまくいくようです。ただし、これにより2つの clean() メソッドが返さcleaned_data
れますが、これは少し奇妙に思えます。
これは正しい方法ですか?