0

Is there an option to create a queryset that outer joins 2 querysets without raw sql?

I have one queryset that hits 1 table -

queryset1 = Model1.objects.all()

I have another queryset that hits the same table and does some aggregation -

queryset2 = Model1.objects.filter(relatedField__days__range=(2013-05-11, 2013-05-13)).annotate(s1=Sum(relatedField__field1), s2=Sum(relatedField__field2))

I want to left outer join the first queryset with the second without raw sql. As you can see, the second queryset is a subset of the first. The problem is, that I want to return all the objects in the table. If an object didn't pass the filter I want to present 0 in the sum fields. That's the reason I want outer join.

Was that clear enough?

ge7600
  • 401
  • 3
  • 8

1 Answers1

0

I don't know off the top of my head but you could probably build an empty model that is a proxy of the original and use that.

https://docs.djangoproject.com/en/dev/topics/db/models/#proxy-models