當前位置: 首頁>>代碼示例>>Python>>正文


Python forms.modelform_factory方法代碼示例

本文整理匯總了Python中django.forms.modelform_factory方法的典型用法代碼示例。如果您正苦於以下問題:Python forms.modelform_factory方法的具體用法?Python forms.modelform_factory怎麽用?Python forms.modelform_factory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.forms的用法示例。


在下文中一共展示了forms.modelform_factory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_classes

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def create_classes(request):
    """ Create classes view """
    ClassFormSet = modelform_factory(
        Semester_Class,
        fields=("semester", "department", "class_number", "class_section"),
    )
    if request.method == "POST":
        formset = ClassFormSet(request.POST)
        if formset.is_valid():
            stock = formset.save(commit=False)
            stock.professor_id = request.user
            stock.save()
            messages.success(request, f"Class Added")
            return redirect("profile")
    else:
        formset = ClassFormSet()

    return render(
        request,
        "gatorgrouper/classes.html",
        {"title": "Create Classes", "formset": formset},
    )


# Allows the user to view the list of assignments 
開發者ID:GatorIncubator,項目名稱:gatorgrouper,代碼行數:27,代碼來源:views.py

示例2: setUp

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def setUp(self):
        self.CalendarForm = modelform_factory(Calendar, fields=("name",)) 
開發者ID:iago1460,項目名稱:django-radio,代碼行數:4,代碼來源:test_schedules.py

示例3: get_form

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def get_form(self):
        config_models = [
            model for model in apps.get_models() if issubclass(model, ByroConfiguration)
        ]
        data = self.request.POST if self.request.method == "POST" else None
        return [
            forms.modelform_factory(
                model, fields="__all__", exclude=("registration_form",)
            )(prefix=model.__name__, instance=model.get_solo(), data=data)
            for model in config_models
        ] 
開發者ID:byro,項目名稱:byro,代碼行數:13,代碼來源:settings.py

示例4: get_form_class

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def get_form_class(self):
        return modelform_factory(
                    self.model,
                    form=ParticipantForm,
                    fields=['name', 'vip', 'email', 'phone_number', 'biography', 'notes'] + ParticipantForm.SOCIAL_FIELDS,
        ) 
開發者ID:PonyConf,項目名稱:PonyConf,代碼行數:8,代碼來源:views.py

示例5: widget_for_object_field

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def widget_for_object_field(obj, field_name):
    FieldForm = modelform_factory(
        obj.source_dynmodel().get_model(),
        fields=(field_name,)
    )
    widget = FieldForm().fields[field_name].widget
    return widget 
開發者ID:propublica,項目名稱:django-collaborative,代碼行數:9,代碼來源:admin.py

示例6: get_form_class

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def get_form_class(self):
        fields = self.object.settings['fields']
        form_class = modelform_factory(self.model, fields=fields)
        return form_class 
開發者ID:vitorfs,項目名稱:colossus,代碼行數:6,代碼來源:views.py

示例7: get_page_form

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def get_page_form(model_ct, form=HelpBasePageForm):
    model = model_ct.model_class()
    assert issubclass(model, models.HelpBasePage) and model != models.HelpBasePage, \
        "Model must be a subclass of HelpBasePage, but not HelpBasePage itself."
    assert model in PAGE_TYPES, "Not a supported model"

    form = forms.modelform_factory(model, form=form, fields=model.admin_fields)
    form.model_ct = model_ct

    return form 
開發者ID:Inboxen,項目名稱:Inboxen,代碼行數:12,代碼來源:forms.py

示例8: _get_model_form_class

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def _get_model_form_class(model_form_class, model_container, admin, request):
    if not model_form_class:
        form_kwargs = dict(
            form=forms.ModelForm,
            fields=forms.ALL_FIELDS,
        )

        if admin and request:
            form_kwargs['formfield_callback'] = functools.partial(
                admin.formfield_for_dbfield, request=request)

        model_form_class = modelform_factory(model_container, **form_kwargs)

    return model_form_class 
開發者ID:nesdis,項目名稱:djongo,代碼行數:16,代碼來源:fields.py

示例9: test_modelform_rendering

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def test_modelform_rendering(self):
        Form = modelform_factory(TestModel, fields=('phone',))
        obj = TestModel(phone='415 123 4567 x 88')
        f = Form(instance=obj)
        self.assertEqual(str(f), _rendered_field_html(phone_number='(415) 123-4567', extension='88', required=True)) 
開發者ID:VeryApt,項目名稱:django-phone-field,代碼行數:7,代碼來源:tests.py

示例10: test_modelform_rendering_nullable

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def test_modelform_rendering_nullable(self):
        Form = modelform_factory(TestModelBlankNull, fields=('phone',))
        obj = TestModel(phone='415 123 4567 x 88')
        f = Form(instance=obj)
        self.assertEqual(str(f), _rendered_field_html(phone_number='(415) 123-4567', extension='88', required=False)) 
開發者ID:VeryApt,項目名稱:django-phone-field,代碼行數:7,代碼來源:tests.py

示例11: test_modelform_saving

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def test_modelform_saving(self):
        Form = modelform_factory(TestModel, fields=('phone',))
        f = Form({'phone_0': '415.123.4567', 'phone_1': '88'})
        self.assertTrue(f.is_valid())
        obj = f.save()
        self.assertIsInstance(obj.phone, PhoneNumber)
        self.assertEqual(str(obj.phone), '(415) 123-4567, press 88') 
開發者ID:VeryApt,項目名稱:django-phone-field,代碼行數:9,代碼來源:tests.py

示例12: test_modelform_empty

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def test_modelform_empty(self):
        Form = modelform_factory(TestModelOptional, fields=('name', 'phone'))
        f = Form({'name': 'Ted', 'phone_0': '', 'phone_1': ''})
        self.assertTrue(f.is_valid())
        obj = f.save()
        self.assertEqual(obj.phone, '') 
開發者ID:VeryApt,項目名稱:django-phone-field,代碼行數:8,代碼來源:tests.py

示例13: get_form_class

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def get_form_class(self):
        return modelform_factory(self.model, form=AddNotificationForm) 
開發者ID:SFDO-Tooling,項目名稱:MetaCI,代碼行數:4,代碼來源:views.py

示例14: get_forms

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def get_forms(self):
        obj = self.get_object()
        membership_create_form = forms.modelform_factory(
            Membership, fields=["start", "end", "interval", "amount"]
        )
        for key in membership_create_form.base_fields:
            setattr(membership_create_form.base_fields[key], "required", False)
        return (
            [
                self._instantiate(
                    forms.modelform_factory(Member, exclude=["membership_type"]),
                    member=obj,
                    instance=obj,
                )
            ]
            + [
                self._instantiate(
                    forms.modelform_factory(Membership, exclude=["member"]),
                    member=obj,
                    instance=m,
                    prefix=m.id,
                )
                for m in obj.memberships.all()
            ]
            + [
                self._instantiate(
                    membership_create_form,
                    member=obj,
                    profile_class=Membership,
                    empty=True,
                )
            ]
            + [
                self._instantiate(
                    forms.modelform_factory(
                        profile_class,
                        fields=[
                            f.name
                            for f in profile_class._meta.fields
                            if f.name not in ["id", "member"]
                        ],
                    ),
                    member=obj,
                    profile_class=profile_class,
                )
                for profile_class in obj.profile_classes
            ]
        ) 
開發者ID:byro,項目名稱:byro,代碼行數:50,代碼來源:members.py

示例15: get_form_class

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import modelform_factory [as 別名]
def get_form_class(self):
        # We want to have different fields for different comrades, but
        # self.fields is shared across all instances of this view, so we can't
        # use that. There's no get_fields() method we can override, either, so
        # the only hook we can use is overriding this method of ModelFormMixin.
        fields = [
            'public_name',
            'nick_name',
            'legal_name',
            'pronouns',
            'pronouns_to_participants',
            'pronouns_public',
        ]

        comrade = self.object

        # was an approved coordinator for a community that had at least one approved participation
        coordinatored = comrade.coordinatorapproval_set.approved().filter(
            community__participation__approval_status=ApprovalStatus.APPROVED,
        )
        # was an approved mentor for some approved project in an approved community
        mentored = comrade.get_mentored_projects().approved().filter(
            project_round__approval_status=ApprovalStatus.APPROVED,
        )
        # was an approved application reviewer at some point
        reviewered = comrade.applicationreviewer_set.approved()

        # people who participated in some way at some time can set a photo of themselves
        if comrade.account.is_staff or comrade.get_intern_selection() is not None or coordinatored.exists() or mentored.exists() or reviewered.exists():
            fields.append('photo')

        fields.extend([
            'timezone',
            'location',
            'nick',
            'github_url',
            'gitlab_url',
            'blog_url',
            'blog_rss_url',
            'twitter_url',
            'agreed_to_code_of_conduct',
        ])
        return modelform_factory(comrade.__class__, fields=fields) 
開發者ID:outreachy,項目名稱:website,代碼行數:45,代碼來源:views.py


注:本文中的django.forms.modelform_factory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。