我的代码设置如下:
class User(models.Model):
email = models.EmailField(_(u'email address'), max_length=255, unique=True, db_index=True, blank=True)
class Verification(models.Model):
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='verifications')
category = models.CharField(choices=constants.VERIFICATION_CATEGORY_CHOICES, default=None, max_length=255)
status = models.CharField(_(u'verification status'), max_length=255, default=constants.STATUS_PENDING, blank=True, null=True)
现在,我需要获取具有“ ID”(类别)验证并且验证状态为“已批准”的用户列表。我该如何实现?
答案 0 :(得分:2)
您可以这样操作(使用related_name verifications
作为反向关系):
User.objects.filter(verifications__category="ID", verifications_status="APPROVED")