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)
精彩评论