我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用django.forms.models.BaseInlineFormSet()。
def get_formset(self, **kwargs): """Returns a BaseInlineFormSet class for use in admin add/change views.""" if self.exclude is None: exclude = [] else: exclude = list(self.exclude) exclude.extend(self.get_readonly_fields()) if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude: # Take the custom ModelForm's Meta.exclude into account only if the # InlineModelAdmin doesn't define its own. exclude.extend(self.form._meta.exclude) # if exclude is an empty list we use None, since that's the actual # default exclude = exclude or None can_delete = self.can_delete and self.has_delete_permission() defaults = { "form": self.form, "formset": self.formset, "fk_name": self.fk_name, 'fields': forms.ALL_FIELDS, "exclude": exclude, "formfield_callback": self.formfield_for_dbfield, "extra": self.extra, "max_num": self.max_num, "can_delete": can_delete, } defaults.update(kwargs) return inlineformset_factory(self.parent_model, self.model, **defaults)
def get_formset(self, **kwargs): """?? BaseInlineFormSet ?""" if self.exclude is None: exclude = [] else: exclude = list(self.exclude) exclude.extend(self.get_readonly_fields()) if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude: # Take the custom ModelForm's Meta.exclude into account only if the # InlineModelAdmin doesn't define its own. exclude.extend(self.form._meta.exclude) # if exclude is an empty list we use None, since that's the actual # default #exclude = exclude or None can_delete = self.can_delete and self.has_delete_permission() defaults = { "form": self.form, "formset": self.formset, "fk_name": self.fk_name, "exclude": exclude, "formfield_callback": self.formfield_for_dbfield, "extra": self.extra, "max_num": self.max_num, "can_delete": can_delete, } defaults.update(kwargs) return inlineformset_factory(self.parent_model, self.model, **defaults)
def fields(self): fk = getattr(self, "fk", None) for field in super(BaseInlineFormSet, self).fields(): if fk and fk.name == field['name']: continue yield field
def get_formset(self, **kwargs): """Returns a BaseInlineFormSet class for use in admin add/change views.""" if self.exclude is None: exclude = [] else: exclude = list(self.exclude) exclude.extend(self.get_readonly_fields()) if self.exclude is None and hasattr(self.form, '_meta') and self.form._meta.exclude: # Take the custom ModelForm's Meta.exclude into account only if the # InlineModelAdmin doesn't define its own. exclude.extend(self.form._meta.exclude) # if exclude is an empty list we use None, since that's the actual # default exclude = exclude or None can_delete = self.can_delete and self.has_delete_permission() defaults = { "form": self.form, "formset": self.formset, "fk_name": self.fk_name, "exclude": exclude, "formfield_callback": self.formfield_for_dbfield, "extra": self.extra, "max_num": self.max_num, "can_delete": can_delete, } defaults.update(kwargs) return inlineformset_factory(self.parent_model, self.model, **defaults)