1
2
3
4
5
|
list_display:控制展示字段,注意不能放多对多字段 list_display_links: 控制跳转字段 search_fields: 配置在前端可用的查询字段,查询字段是或关系 list_filter: 设置过滤字段,建议放外键字段用来做过滤并且上下是 and 关系 actions:批量处理函数 |
例如:
1 class BookConfig(admin.ModelAdmin): 2 list_display = ['title', 'price', 'publish_date', 'publish'] 3 list_display_links = ['title', 'price'] 4 search_fields = ['title', 'price'] 5 list_filter = ['publish', 'authors'] 6 7 def patch_init(self, reqquest, queryset): 8 queryset.update(price=666) 9 10 patch_init.short_description = '价格批量修改' 11 actions = [patch_init] 12 13 14 admin.site.register(models.Book, BookConfig)