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


Python ModelAdmin.get_form方法代码示例

本文整理汇总了Python中django.contrib.admin.ModelAdmin.get_form方法的典型用法代码示例。如果您正苦于以下问题:Python ModelAdmin.get_form方法的具体用法?Python ModelAdmin.get_form怎么用?Python ModelAdmin.get_form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.admin.ModelAdmin的用法示例。


在下文中一共展示了ModelAdmin.get_form方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_form

# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import get_form [as 别名]
 def get_form(self, request, obj=None, **kwargs):
     if request.method == 'POST' and obj is None:
         try:
             request.POST['dispatcher'] = Dispatcher.objects.get(name__iexact=u' '.join((request.user.last_name, request.user.first_name)))
         except:
             pass
     return ModelAdmin.get_form(self, request, obj=obj, **kwargs)
开发者ID:keeran6,项目名称:check-logist,代码行数:9,代码来源:admin.py

示例2: test_admin_forms

# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import get_form [as 别名]
    def test_admin_forms(self):
        site = AdminSite()
        model_admin = ModelAdmin(IntModel, site)
        form_clazz = model_admin.get_form(None)
        form_instance = form_clazz()

        try:
            form_instance.as_table()
        except TypeError:
            self.fail('HTML Rendering of the form caused a TypeError')
开发者ID:nwp90,项目名称:djorm-ext-pgarray,代码行数:12,代码来源:tests.py

示例3: app_settings

# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import get_form [as 别名]
 def app_settings(self, request, app_name):
     model_classes = registered_settings.get(app_name)
     if not model_classes:
         raise Http404
     forms = []
     fieldsets = []
     model_admin = ModelAdmin(Root, self)
     for model_name, model in model_classes.items():
         instance = getattr(settings, '%s_%s' % (app_name, model_name))
         model_admin = self.registered_settings.get(model)
         if not model_admin:
             model_admin = ModelAdmin(model, self)
         form_class = model_admin.get_form(request, instance)
         form = form_class(
             prefix=model_name,
             data=request.POST or None,
             instance=instance
         )
         forms.append(form)
         meta = getattr(model, '_meta')
         name = '%s %s' % (app_name.title(), meta.verbose_name)
         readonly_fields = model_admin.readonly_fields
         fields = list(form.fields.keys()) + list(readonly_fields)
         fs = Fieldset(form, name, readonly_fields, fields)
         fieldsets.append(fs)
     # list comprehension to evaluate all forms
     if all([form.is_valid() for form in forms]):
         for form in forms:
             form.save()
         msg = '%s settings have been saved.' % app_name.title()
         messages.info(request, msg)
         if '_save' in request.POST:
             url = reverse('admin:settings', current_app=self.name)
             return redirect(url)
         return redirect(request.get_full_path())
     context = {
         'app_name': app_name.title(),
         'forms': forms,
         'fieldsets': fieldsets,
         'opts': FakeOpts(),
         'change': True,
         'is_popup': False,
         'save_as': False,
         'has_add_permission': False,
         'has_delete_permission': False,
         'has_change_permission': True,
         'media': model_admin.media,
     }
     return TemplateResponse(
         request,
         'admin/dbsettings/app_settings.html',
         context,
         current_app=self.name
     )
开发者ID:Pentusha,项目名称:django-modelsettings,代码行数:56,代码来源:admin.py

示例4: get_form

# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import get_form [as 别名]
    def get_form(self, request, obj=None, **kwargs):
        """
        Push request into the ModelForm. Requires the form to override __init__
        and remove request from the kwargs.
        See: http://stackoverflow.com/questions/1057252/how-do-i-access-the-request-object-or-any-other-variable-in-a-forms-clean-met
        """
        ModelForm = ModelAdmin.get_form(self, request, obj, **kwargs)

        class ModelFormWithRequestWrapper(ModelForm):
            """class wrapping actual model form class to capture request"""
            def __new__(cls, *args, **kwargs):
                kwargs['request'] = request
                return ModelForm(*args, **kwargs)

        return ModelFormWithRequestWrapper
开发者ID:graik,项目名称:rotmic,代码行数:17,代码来源:adminBase.py

示例5: test_confirm_email

# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import get_form [as 别名]
    def test_confirm_email(self):
        ecla_admin = ModelAdmin(EmailConfirmation, self.site)
        ecla_form = ecla_admin.get_form(request)

        self.assertIn('email_field_name', ecla_form.base_fields.keys())
        self.assertIn('email', ecla_form.base_fields.keys())
开发者ID:vinta,项目名称:django-email-confirm-la,代码行数:8,代码来源:test_admin.py


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