我有一个表格:
class RideForm(forms.Form):
# a lot of field
# fields accorded to geography
# fields accorded to condition
def clean(self, *args, **kwargs):
# clean of all fields
我想像这样拆分它(这只是一个概念,我写这个只是为了说明想法)。:
class RideGeographyPartForm(...):
# fields accorded to geography
def clean(self, *args, **kwargs):
# clean only geography group of field
class RideConditionPartForm(...):
# fields accorded to condition
def clean(self, *args, **kwargs):
# clean only geography group of field
class RideForm(RideGeographyPartForm, RideConditionPartForm, forms.Form):
def clean(self, *args, **kwargs):
# this should internaly call all clean logic from
# RideGeographyPartForm, RideConditionPartForm
我现在不知道如何做到这一点。我尝试使用 mixin,但在字段初始化方面遇到了一些问题,应该兼顾调用内部方法。我可以使用抽象模型文档对模型做类似的事情。有没有办法做这种组合但有形式?