django amdin页面下拉列表的外键增加条件过滤

class MenuList(admin.ModelAdmin):
list_display = ('menuId', 'menuName', 'menuDesc', 'menuType', 'sort_order') def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == 'status': #外键字段
kwargs["queryset"] = DictItem.objects.filter(groupId='menustatus')
return super(MenuList, self).formfield_for_foreignkey(db_field, request, **kwargs)
上一篇:Vscode 格式化vue Template代码段


下一篇:在论坛中出现的比较难的sql问题:10(删除多表中的同一个外键)