本文整理汇总了Python中django.forms.models.BaseInlineFormSet方法的典型用法代码示例。如果您正苦于以下问题:Python models.BaseInlineFormSet方法的具体用法?Python models.BaseInlineFormSet怎么用?Python models.BaseInlineFormSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms.models
的用法示例。
在下文中一共展示了models.BaseInlineFormSet方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_formset
# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import BaseInlineFormSet [as 别名]
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)
示例2: save
# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import BaseInlineFormSet [as 别名]
def save(self, commit=True):
obj = super(BaseInlineFormSet, self).save(commit=False)
self._pre_save(obj)
if commit:
obj.save()
self._set_post_save(commit, obj)
return obj
示例3: smartinlineformset_factory
# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import BaseInlineFormSet [as 别名]
def smartinlineformset_factory(parent_model, model, request, form=ModelForm,
formset=BaseInlineFormSet, fk_name=None,
fields=None, exclude=None, extra=3, can_order=False,
can_delete=True, min_num=None, max_num=None, formfield_callback=None,
widgets=None, validate_min=False, validate_max=False, localized_fields=None,
labels=None, help_texts=None, error_messages=None,
formreadonlyfield_callback=None, readonly_fields=None,
readonly=False):
fk = _get_foreign_key(parent_model, model, fk_name=fk_name)
# enforce a max_num=1 when the foreign key to the parent model is unique.
if fk.unique:
max_num = 1
kwargs = {
'form': form,
'formfield_callback': formfield_callback,
'formset': formset,
'extra': extra,
'can_delete': can_delete,
'can_order': can_order,
'fields': fields,
'exclude': exclude,
'max_num': max_num,
'min_num': min_num,
'widgets': widgets,
'validate_min': validate_min,
'validate_max': validate_max,
'localized_fields': localized_fields,
'labels': labels,
'help_texts': help_texts,
'error_messages': error_messages,
'formreadonlyfield_callback': formreadonlyfield_callback,
'readonly_fields': readonly_fields,
'readonly': readonly,
}
FormSet = smartmodelformset_factory(model, request, **kwargs)
FormSet.fk = fk
return FormSet