<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 中的动态表单

      时间:2023-11-07
    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 中的动态表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在admin django 1.6中注册抽象模型 下一篇:有人使用 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>

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