# admin.py class InnerOrderAdmin(admin.ModelAdmin): ... # 外键关联下拉框 筛选 def formfield_for_foreignkey(self, db_field, request, **kwargs): if db_field.name == "technology_user": # 外键字段 kwargs["queryset"] = AdminUser.objects.filter(groups__name="技术") # 只能选择是技术这个角色的关联 return super(InnerOrderAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
标签:Admin,db,外键,关联,field,kwargs,下拉框 From: https://www.cnblogs.com/wanghong1994/p/16757576.html