當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。