{{{
Teacher.objects.exclude(student__age=20, student__note__lt=5).query
}}}
Which will results in this query:
{{{
SELECT "teachers_teacher"."id", "teachers_teacher"."name" FROM
"teachers_teacher" WHERE NOT ("teachers_teacher"."id" IN (SELECT
U1."teacher_id" AS Col1 FROM "teachers_student" U1 WHERE U1."age" = 20)
AND "teachers_teacher"."id" IN (SELECT U1."teacher_id" AS Col1 FROM
"teachers_student" U1 WHERE U1."note" < 5))
}}}
I think the right SQL will be the following:
{{{
SELECT "teachers_teacher"."id", "teachers_teacher"."name" FROM
"teachers_teacher" WHERE NOT ("teachers_teacher"."id" IN (SELECT
U1."teacher_id" AS Col1 FROM "teachers_student" U1 WHERE U1."age" = 20 AND
U1."note" < 5))
}}}
Even if the fix will be need a lot of work, I think it's better to mention
this in the exclude documentation.
--
Ticket URL: <https://code.djangoproject.com/ticket/27727>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => duplicate
Comment:
I believe that's a duplicate of #14645.
[https://docs.djangoproject.com/en/stable/topics/db/queries/#spanning-
multi-valued-relationships The documentation] already contains a note
about it.
--
Ticket URL: <https://code.djangoproject.com/ticket/27727#comment:1>
Comment (by Mounir):
Thank you and sorry for the duplicate, I would suggest to mention this in
the documentation of the
[https://docs.djangoproject.com/en/1.10/ref/models/querysets/#django.db.models.query.QuerySet.exclude
exclude]
Replying to [comment:1 Tim Graham]:
> I believe that's a duplicate of #14645.
[https://docs.djangoproject.com/en/stable/topics/db/queries/#spanning-
multi-valued-relationships The documentation] already contains a note
about it.
--
Ticket URL: <https://code.djangoproject.com/ticket/27727#comment:2>