<legend id='jG3f6'><style id='jG3f6'><dir id='jG3f6'><q id='jG3f6'></q></dir></style></legend>

    <small id='jG3f6'></small><noframes id='jG3f6'>

      <bdo id='jG3f6'></bdo><ul id='jG3f6'></ul>
  1. <tfoot id='jG3f6'></tfoot>

      <i id='jG3f6'><tr id='jG3f6'><dt id='jG3f6'><q id='jG3f6'><span id='jG3f6'><b id='jG3f6'><form id='jG3f6'><ins id='jG3f6'></ins><ul id='jG3f6'></ul><sub id='jG3f6'></sub></form><legend id='jG3f6'></legend><bdo id='jG3f6'><pre id='jG3f6'><center id='jG3f6'></center></pre></bdo></b><th id='jG3f6'></th></span></q></dt></tr></i><div id='jG3f6'><tfoot id='jG3f6'></tfoot><dl id='jG3f6'><fieldset id='jG3f6'></fieldset></dl></div>

      django-admin 中的动态表单

      Dynamic forms in django-admin(django-admin 中的动态表单)
    1. <legend id='UIUPJ'><style id='UIUPJ'><dir id='UIUPJ'><q id='UIUPJ'></q></dir></style></legend>
    2. <i id='UIUPJ'><tr id='UIUPJ'><dt id='UIUPJ'><q id='UIUPJ'><span id='UIUPJ'><b id='UIUPJ'><form id='UIUPJ'><ins id='UIUPJ'></ins><ul id='UIUPJ'></ul><sub id='UIUPJ'></sub></form><legend id='UIUPJ'></legend><bdo id='UIUPJ'><pre id='UIUPJ'><center id='UIUPJ'></center></pre></bdo></b><th id='UIUPJ'></th></span></q></dt></tr></i><div id='UIUPJ'><tfoot id='UIUPJ'></tfoot><dl id='UIUPJ'><fieldset id='UIUPJ'></fieldset></dl></div>
        <tfoot id='UIUPJ'></tfoot>
          • <bdo id='UIUPJ'></bdo><ul id='UIUPJ'></ul>

              <small id='UIUPJ'></small><noframes id='UIUPJ'>

                  <tbody id='UIUPJ'></tbody>
                本文介绍了django-admin 中的动态表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想让管理员添加表单动态化.我想根据相关对象中的设置添加一些表单域.

                I want to make admin add-form dynamic. I want to add few formfields depending on setting in related object.

                我有这样的事情:

                class ClassifiedsAdminForm(forms.ModelForm):
                
                
                  def __init__(self,*args, **kwargs):
                     super(ClassifiedsAdminForm, self).__init__(*args, **kwargs)
                     self.fields['testujemy'] = forms.CharField(label = "test")
                

                在 admin.py 中:

                And in admin.py:

                class ClassifiedAdmin(admin.ModelAdmin):
                     def get_form(self, request, obj=None, **kwargs):
                         return ClassifiedsAdminForm
                

                如您所见,我想将testujemy"CharField 添加到管理员添加表单和更改表单.然而,这种方式行不通.有没有办法在 init 中添加字段?它在正常视图下工作.

                As you can see, I want to add "testujemy" CharField to admin add-form and change-form. However, this way doesnt work. Is there any way to add field in init? It is working in normal view.

                推荐答案

                我已经设法使用 type() 做到了.

                I've managed to do it using type().

                class ClassifiedAdmin(admin.ModelAdmin):
                
                 def get_form(self, request, obj=None, **kwargs):
                
                    adminform = ClassifiedsAdminForm()
                    fields = adminform.getNewFields()
                
                    form = type('ClassifiedsAdminForm', (forms.ModelForm,), fields)
                
                    return form
                

                希望对某人有所帮助.

                这篇关于django-admin 中的动态表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
                  • <bdo id='LQ01t'></bdo><ul id='LQ01t'></ul>
                    <i id='LQ01t'><tr id='LQ01t'><dt id='LQ01t'><q id='LQ01t'><span id='LQ01t'><b id='LQ01t'><form id='LQ01t'><ins id='LQ01t'></ins><ul id='LQ01t'></ul><sub id='LQ01t'></sub></form><legend id='LQ01t'></legend><bdo id='LQ01t'><pre id='LQ01t'><center id='LQ01t'></center></pre></bdo></b><th id='LQ01t'></th></span></q></dt></tr></i><div id='LQ01t'><tfoot id='LQ01t'></tfoot><dl id='LQ01t'><fieldset id='LQ01t'></fieldset></dl></div>

                    <small id='LQ01t'></small><noframes id='LQ01t'>

                    <legend id='LQ01t'><style id='LQ01t'><dir id='LQ01t'><q id='LQ01t'></q></dir></style></legend>

                        <tbody id='LQ01t'></tbody>

                          <tfoot id='LQ01t'></tfoot>