添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
朝气蓬勃的柿子  ·  FastAPI with Django ...·  昨天    · 
聪明的啤酒  ·  Python Web Frameworks ...·  昨天    · 
成熟的打火机  ·  Motivation - Django Ninja·  昨天    · 
忐忑的铁板烧  ·  GitHub - ...·  昨天    · 
奔跑的香烟  ·  Building APIs using ...·  昨天    · 
虚心的排球  ·  Solved: Path to ...·  3 月前    · 
独立的小狗  ·  .NET Core Best ...·  4 月前    · 

https://stackoverflow.com/questions/30214469/in-django-admin-how-to-add-filter-or-search-for-foreign-key-select-box/50356922

With this you can use the autocomplete_fields on a foreignkey field on your source admin class and as before set the search_fields on the target admin class.

配置 admin

class AnchorBindAgentAdmin(admin.ModelAdmin): list_display = ["agent", "anchor", "proportion", "start_time", "end_time", "create_time"] list_display_links = ["agent", "anchor", "proportion", "start_time", "end_time", "create_time"] list_filter = ["agent", "anchor", "start_time", "end_time"] list_per_page = 20 # 每页数量 readonly_fields = ["start_time"] autocomplete_fields = ["anchor"] # 带有搜索框的外键选择框

配置后效果

被搜索的字段需要在其对应对的模型的 admin 中加入到 search_field

  • HINT: It seems you set a fixed date / time / datetime value as default for this field. This may not be what you want. If you want to have the current date as default, use `django.utils.timezone.now`
  • django admin 列表禁用删除操作,编辑页面禁用删除按钮
  • django assignment_tag 赋值标签
  • django 获取 request 的 url
  •