how to subquery in queryset in django?

as mentioned by ypercube your use case doesn’t require subquery.

but anyway since many people land into this page to learn how to do sub-query here is how its done.

employee_query = Employee.objects.filter(company='Private').only('id').all()
Person.objects.value('name', 'age').filter(id__in=employee_query)

Source:
http://mattrobenolt.com/the-django-orm-and-subqueries/

Leave a Comment

File not found.