I am writing a method that computes a complex Django QuerySet.
It starts like this
qs1 = A.objects.filter(b_set__c_obj__user=user)
qs1will eventually become the result, but before it does, the method goes on with several further steps of filtering and annotation.b_setis an 1:n relationship, but I know that at most one of thec_objcan actually match.- I need to reference this
c_obj, because I need another attributeemailfrom it for one of the filtering steps (which is against instances of another modelDselected based onc_obj'semail). usercan be either aUsermodel instance or anOuterRefDjango ORM expression, because the whole queryset created by the method is subsequently also to be used in a subquery.- Therefore, any solution that involves evaluating querysets is not suitable for me. I can only build a single queryset.
Hmm?