添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
挂过科的肉夹馍  ·  Understanding Django ...·  12 小时前    · 
考研的台灯  ·  Redis instance for ...·  3 天前    · 
爱看书的签字笔  ·  常用 Django QuerySet ...·  3 天前    · 
犯傻的毛衣  ·  Django admin ...·  3 天前    · 
千杯不醉的跑步鞋  ·  社区中心·  2 月前    · 
茫然的青椒  ·  GitHub - amoffat/sh: ...·  3 月前    · 

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
  •