<legend id='bAvBs'><style id='bAvBs'><dir id='bAvBs'><q id='bAvBs'></q></dir></style></legend>
    <bdo id='bAvBs'></bdo><ul id='bAvBs'></ul>

<tfoot id='bAvBs'></tfoot>
    1. <small id='bAvBs'></small><noframes id='bAvBs'>

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

        如何在 Django-admin 中添加自定义搜索框?

        时间:2023-11-08
              <tbody id='XLZQP'></tbody>

            <tfoot id='XLZQP'></tfoot>

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

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

                  <legend id='XLZQP'><style id='XLZQP'><dir id='XLZQP'><q id='XLZQP'></q></dir></style></legend>
                1. 本文介绍了如何在 Django-admin 中添加自定义搜索框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我知道这将是一个非常基本的问题.

                  I know this is gonna be a very basic question.

                  在 Django 中,我已经成功创建了一个管理面板.现在我想在我的一个字段中添加一个自定义搜索框,即 Photo 字段.但我不知道如何在 django-admin 面板中添加自定义搜索框.如果我得到一些适当的提示,我相信我可以做到.

                  In Django, I have successfully created an admin panel. Now I want to add a custom search box in one of my field namely Photo field. But I don't know how to add custom search box in a django-admin panel. If I get some proper hints than I believe that I can do it.

                  Admin.py:

                  from django.contrib import admin
                  
                  
                  from photo.models import Photo,
                  
                  class PhotoAdmin(admin.ModelAdmin):
                  
                      list_display=('name','approved','approved_time','uploaded_time','user')
                  

                  models.py:

                  class Photo(models.Model):
                      name = models.CharField(max_length = 100)
                      photo = models.ImageField(upload_to = 'photos', blank=False,null=True)
                      approved = models.BooleanField(default = False)
                      approved_time = models.DateTimeField(auto_now=True,null=True,blank=True)
                      uploaded_time = models.DateTimeField()
                      description = models.CharField(max_length = 500 , blank = False , null = True)
                  keyword = models.CharField(max_length = 500 , blank = False , null = True)
                      image_id = models.CharField(max_length=300, blank=True, null=True)
                      Certified = models.BooleanField(default = False)
                      approved_by = models.CharField(max_length = 100)
                      user = models.ForeignKey(User)
                      total_download = models.IntegerField(default=0)
                      watermarked_image = models.ImageField(upload_to = 'temp', blank=True,null=True)
                  

                  我想在这个 Photo 字段中添加一个自定义搜索框,可以通过它的 ID 搜索图像.现在我如何在上面给出的添加这个搜索框型号.

                  I want to add a custom search box in this Photo field where image can be searched by it's ID.Now how can I add this search box in my above given model.

                  推荐答案

                  使用ModelAdmin 的 .ModelAdmin.search_fields" rel="noreferrer">search_fields 属性:

                  Use the search_fields attribute of the ModelAdmin:

                  class PhotoAdmin(admin.ModelAdmin):
                      ...
                      search_fields = ['name', 'description', 'user__related_fieldname','keyword', ]
                  

                  这篇关于如何在 Django-admin 中添加自定义搜索框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Django 管理员:仅在更改表单上排除字段 下一篇:姜戈.您无权编辑任何内容

                  相关文章

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

                  <small id='1IMFv'></small><noframes id='1IMFv'>

                    <legend id='1IMFv'><style id='1IMFv'><dir id='1IMFv'><q id='1IMFv'></q></dir></style></legend>
                  1. <tfoot id='1IMFv'></tfoot>