• <small id='wsI1H'></small><noframes id='wsI1H'>

    <tfoot id='wsI1H'></tfoot><legend id='wsI1H'><style id='wsI1H'><dir id='wsI1H'><q id='wsI1H'></q></dir></style></legend>

    • <bdo id='wsI1H'></bdo><ul id='wsI1H'></ul>

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

        Django 管理员.在更改选择字段上隐藏字段

        Django admin. Hide field on change select field(Django 管理员.在更改选择字段上隐藏字段)
        <legend id='k73Yn'><style id='k73Yn'><dir id='k73Yn'><q id='k73Yn'></q></dir></style></legend>
        <tfoot id='k73Yn'></tfoot>

          <bdo id='k73Yn'></bdo><ul id='k73Yn'></ul>
            <tbody id='k73Yn'></tbody>

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

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

                • 本文介绍了Django 管理员.在更改选择字段上隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有模特:

                  class CategoryField(models.Model):
                      selectfield = models.IntegerField(choices=SELECT_FIELD_CHOICES, default=1)
                      verified = models.BooleanField(default=True, verbose_name='Required?')
                  

                  在管理页面我有 selectField 选项:value1",value2",value3",...当我选择value2"时,我需要显示 verified 字段.我该怎么做?

                  In admin page I have selectField with choices: "value1", "value2", "value3", ... When I select "value2" I need to show verified field. How can I do it?

                  推荐答案

                  您需要添加一些 JavaScript 才能显示或隐藏该字段.jQuery 1.9.1 已经通过 在 Django admin 中可用django.jQuery 对象.

                  You would need to add some JavaScript in order to show or hide the field. jQuery 1.9.1 is available in Django admin already via the django.jQuery object.

                  添加此 JavaScript 的最简单方法是添加 媒体 元类到您的模型表单并将表单添加到 ModelAdmin:

                  The simplest way to add this JavaScript is to add a Media meta class to your model form and add the form to the ModelAdmin:

                  # forms.py
                  
                  from django import forms
                  
                  class CategoryFieldForm(forms.ModelForm):
                      . . .
                  
                      class Media:
                          js = ('category-field-admin.js',)
                  
                  
                  # admin.py
                  
                  from django.contrib import admin
                  
                  from your_app.forms import CategoryFieldForm
                  from your_app.models import CategoryField
                  
                  
                  class CategoryFieldAdmin(admin.ModelAdmin):
                      form = CategoryFieldForm
                  
                  
                  admin.site.register(CategoryField, CategoryFieldAdmin)
                  
                  
                  # category-field-admin.js
                  
                  // pseudo code - change as needed
                  
                  (function($) {
                      $(function() {
                          var selectField = $('#id_selectField'),
                              verified = $('#id_verified');
                  
                          function toggleVerified(value) {
                              value == 'value2' ? verified.show() : verified.hide();
                          }
                  
                          // show/hide on load based on pervious value of selectField
                          toggleVerified(selectField.val());
                  
                          // show/hide on change
                          selectField.change(function() {
                              toggleVerified($(this).val());
                          });
                      });
                  })(django.jQuery);
                  

                  这篇关于Django 管理员.在更改选择字段上隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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中的另一个文件中查找一个文本文件的条目)
                • <i id='npJGj'><tr id='npJGj'><dt id='npJGj'><q id='npJGj'><span id='npJGj'><b id='npJGj'><form id='npJGj'><ins id='npJGj'></ins><ul id='npJGj'></ul><sub id='npJGj'></sub></form><legend id='npJGj'></legend><bdo id='npJGj'><pre id='npJGj'><center id='npJGj'></center></pre></bdo></b><th id='npJGj'></th></span></q></dt></tr></i><div id='npJGj'><tfoot id='npJGj'></tfoot><dl id='npJGj'><fieldset id='npJGj'></fieldset></dl></div>

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

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

                      <tbody id='npJGj'></tbody>
                      • <bdo id='npJGj'></bdo><ul id='npJGj'></ul>

                          <tfoot id='npJGj'></tfoot>