开发者

Django queryset excluding many to many objects

开发者 https://www.devze.com 2023-04-10 12:46 出处:网络
Let\'s assume we have a model: class a(models.Model): users = models.ManyToManyField(User) # django.contrib.auth.models.User

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

精彩评论

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