我知道这将是一个非常基本的问题。
在Django中,我已经成功创建了一个管理面板。现在,我想在我的一个字段即Photo
字段中添加一个自定义搜索框。但是我不知道如何在django-admin面板中添加自定义搜索框。如果我得到一些适当的提示,我相信我可以做到。
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
搜索图像。现在,如何在上述给定模型中添加此搜索框。 最佳答案
使用search_fields
的 ModelAdmin
属性:
class PhotoAdmin(admin.ModelAdmin):
...
search_fields = ('name', 'description', 'keyword', )
关于python - 如何在Django-admin中添加自定义搜索框?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28512710/