本文整理汇总了Python中django.forms.models.BaseModelFormSet方法的典型用法代码示例。如果您正苦于以下问题:Python models.BaseModelFormSet方法的具体用法?Python models.BaseModelFormSet怎么用?Python models.BaseModelFormSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms.models
的用法示例。
在下文中一共展示了models.BaseModelFormSet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_invalid_type
# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import BaseModelFormSet [as 别名]
def test_invalid_type(self):
class FakeFormSet:
pass
class ValidationTestInline(TabularInline):
model = ValidationTestInlineModel
formset = FakeFormSet
class TestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
self.assertIsInvalid(
TestModelAdmin, ValidationTestModel,
"The value of 'formset' must inherit from 'BaseModelFormSet'.",
'admin.E206',
invalid_obj=ValidationTestInline
)
示例2: test_valid_case
# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import BaseModelFormSet [as 别名]
def test_valid_case(self):
class RealModelFormSet(BaseModelFormSet):
pass
class ValidationTestInline(TabularInline):
model = ValidationTestInlineModel
formset = RealModelFormSet
class TestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
self.assertIsValid(TestModelAdmin, ValidationTestModel)
示例3: test_inline_without_formset_class
# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import BaseModelFormSet [as 别名]
def test_inline_without_formset_class(self):
class ValidationTestInlineWithoutFormsetClass(TabularInline):
model = ValidationTestInlineModel
formset = 'Not a FormSet Class'
class TestModelAdminWithoutFormsetClass(ModelAdmin):
inlines = [ValidationTestInlineWithoutFormsetClass]
self.assertIsInvalid(
TestModelAdminWithoutFormsetClass, ValidationTestModel,
"The value of 'formset' must inherit from 'BaseModelFormSet'.",
'admin.E206',
invalid_obj=ValidationTestInlineWithoutFormsetClass
)
示例4: smartmodelformset_factory
# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import BaseModelFormSet [as 别名]
def smartmodelformset_factory(model, request, form=ModelForm, formfield_callback=None,
formset=BaseModelFormSet, extra=1, can_delete=False,
can_order=False, min_num=None, max_num=None, fields=None, exclude=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):
meta = getattr(form, 'Meta', None)
if meta is None:
meta = type(str('Meta'), (object,), {})
if getattr(meta, 'fields', fields) is None and getattr(meta, 'exclude', exclude) is None:
warnings.warn("Calling modelformset_factory without defining 'fields' or "
"'exclude' explicitly is deprecated",
PendingDeprecationWarning, stacklevel=2)
form = smartmodelform_factory(
model, request, form=form, fields=fields, exclude=exclude, formfield_callback=formfield_callback,
widgets=widgets, 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 = smartformset_factory(
form, formset, extra=extra, min_num=min_num, max_num=max_num, can_order=can_order, can_delete=can_delete,
validate_min=validate_min, validate_max=validate_max
)
FormSet.model = model
return FormSet