I have two different queries on the same model that are in essence like this:
queryset_1 = models.Plan.object.filter(name__startswith='a').annotate(group=Value('Group A', output_field=CharField()))
queryset_2 = models.Plan.object.filter(name__startswith='b').annotate(group=Value('Group B', output_field=CharField()))
and when I try
queryset = queryset_1 | queryset_2
only one of those annotations appears to exist. All rows returned have group set to "Group A" and when I inspect the sql it turns out that django only "or"-ing the filters. It send something like:
SELECT plan_plan.*, "Group A" AS "group" FROM plan_plan WHERE ("plan_plan"."name" LIKE 'a%s' OR "plan_plan"."name" LIKE 'b%s');
Is there any way to get a true union instead of an or here? I'm not particularly interested in using raw sql because in the actual application the filters are dynamic a considerably more complicated.
Thanks in advance,
Cameron Derwin