def formset_class(self):
formset_class = inlineformset_factory(
RealTransaction, VirtualTransaction, form=VirtualTransactionForm,
formset=BaseModelFormSet, can_delete=True, extra=0,
)
return formset_class
python类BaseModelFormSet()的实例源码
def formset(self):
formset_class = inlineformset_factory(
Submission, Resource, form=ResourceForm, formset=BaseModelFormSet,
can_delete=True, extra=0,
)
obj = self.get_object()
return formset_class(
self.request.POST if self.request.method == 'POST' else None,
files=self.request.FILES if self.request.method == 'POST' else None,
queryset=obj.resources.all() if obj else Resource.objects.none(),
prefix='resource',
)
def validate_formset(self, cls, model):
" Validate formset is a subclass of BaseModelFormSet. "
if hasattr(cls, 'formset') and not issubclass(cls.formset, BaseModelFormSet):
raise ImproperlyConfigured("'%s.formset' does not inherit from "
"BaseModelFormSet." % cls.__name__)