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
- [Answer]-I18n and l10n in Django with different views
- [Answer]-How to make a record read-only in a Django form?
- [Answer]-How to make form field blank after submitting
- [Answer]-Single Address Linked to Multiple Users Even when Using OneToOneField(User)
- [Answer]-How to avoid cleaned_data for each field if I have too many fields in the form
Source:stackexchange.com