class ModelFilter(admin.SimpleListFilter):
# 选项 label
title = 'model'
parameter_name = 'model'
def lookups(self, request, model_admin):
# 选项 list
model_data = MotorModelData.objects.filter(is_show=1, is_delete=0)
return [(i.id, i.model_name) for i in model_data]
def queryset(self, request, queryset):
# self.value() 选项value 返回queryset对象
if not self.value():
return queryset
return queryset.filter(model_id=self.value())
django admin 外键 list_filter
最新推荐文章于 2023-08-16 16:06:41 发布
关键词由CSDN通过智能技术生成