1 回答
TA贡献1805条经验 获得超10个赞
在 app2 models.py 文件中添加一个字段以将用户类型存储在订单表中:
from app1.models import UserTypes
user = models.OneToOneField(UserTypes, on_delete=models.CASCADE)
将此代码添加到您的 app2 的 admin.py 文件中:
from app1.models import UserTypes
from .models import Order
class OrderAdmin(admin.ModelAdmin):
def get_form(self, request, obj=None, **kwargs):
form = super(OrderAdmin,self).get_form(request, obj,**kwargs)
# form class is created per request by modelform_factory function
# so it's safe to modify
# we modify the the queryset
form.base_fields['user'].queryset =
form.base_fields['user'].queryset.filter(staff_choices='Delivery Boy')
return form
admin.site.register(Order, OrderAdmin)
添加回答
举报