当 ForeignKey 数据过多,手动在后台添加时不方便找到自己的想要数据,遂想要一个可以搜索检索数据功能。
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.
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