我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用django.forms.models.BaseModelFormSet()。
def formset_class(self): formset_class = inlineformset_factory( RealTransaction, VirtualTransaction, form=VirtualTransactionForm, formset=BaseModelFormSet, can_delete=True, extra=0, ) return formset_class
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__)