我有以下型号。我需要获取订单的查询集,其中用户的userprofile.setupstatus ==1。这是否可行,还是应该在Order模型上向UserProfile添加外键字段?
class Order(models.Model):
user = models.ForeignKey(UserCheckout, null=True, on_delete=models.CASCADE)
class UserCheckout(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True, blank=True)
class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
setupstatus = models.IntegerField(default=0)
答案 0 :(得分:1)