[Answer]-Django: exclude User list from all Users

1👍

You need to use the in operator:

User.objects.exclude(id__in=self.users.all())

By using an unevaluated queryset (self.users.all()), it is transformed in a subquery, so the result will be fetched in a single query.

👤knbk

0👍

Maybe something like this:

User.objects.all().exclude(id__in=[u.id for u in self.users.all()])
👤Juca

Leave a comment