当前位置: 首页>>代码示例>>Python>>正文


Python models.BaseModelFormSet方法代码示例

本文整理汇总了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
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:19,代码来源:test_checks.py

示例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) 
开发者ID:nesdis,项目名称:djongo,代码行数:14,代码来源:test_checks.py

示例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
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:16,代码来源:test_checks.py

示例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 
开发者ID:matllubos,项目名称:django-is-core,代码行数:30,代码来源:models.py


注:本文中的django.forms.models.BaseModelFormSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。