Where can I find some information about building a query like this:
select
SomeField1,
(select count(distinct SomeField2) from SomeTable where SomeCondition) as SomeField3
from
SomeTable2
where
SomeCondition2
using Django ORM? It’s probably in the Django documentation somewhere but I can’t find it.
What’s the relationship of your two tables?
I guess you need the count,there is a code snippet without check,
See https://docs.djangoproject.com/en/dev/ref/models/querysets/#annotate and How to sort by annotated Count() in a related model in Django for more details.