开发者

Django queryset excluding many to many objects

Let's assume we have a model:

 class a(models.Model):
     users = models.ManyToManyField(User) # django.contrib.auth.models.User

and these variables:

user = request.user
queryset = a.objects.all()

Then I want to exclud开发者_Python百科e these records from a model that contains the user in users. How can I do that?

queryset.exclude(...)


It's as simple as this:

queryset.exclude(users=user)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜