Not possible to filter authors that have books other than hardcover
|Reported by:||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.3|
|Cc:||mbertheau@…, anssi.kaariainen@…||Triage Stage:||Unreviewed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
It seems that the Django ORM cannot express in one query
SELECT a.* FROM author AS a JOIN book AS b ON b.author_id = a.id WHERE b.bound <> 'hardcover' GROUP BY a.id
that is all authors that have at least one book that is not hardcover.
Both exclude(bookbound='hardcover') and filter(~Q(bookbound='hardcover')) leave only authors that had no hardcover books at all.
A field lookup 'not equal' could be provided with that meaning. Alternatively, the meaning of filter(~Q(bookbound='hardcover')) could be changed.