我有疑问:
users_to_exclude = MyModel.objects.filter(status=1)
现在:
result = MyAnotherModel.objects.filter(image=my_image).count()
和
result = MyAnotherModel.objects.filter(image=my_image).exclude(user__in=users_to_exclude).count()
显示相同的数字(users_to_exclude
有正确的数据)。怎么做得好?
答案 0 :(得分:1)
阅读该主题:
https://docs.djangoproject.com/en/dev/ref/models/querysets/#in
并且有:
You can also use a queryset to dynamically evaluate the list of values instead of providing a list of literal values: