当前位置: 首页>>代码示例>>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;未经允许,请勿转载。