I am trying to do some work like aggregation on a model in django using annotate
andCase
So, I have something like the following ( q
already filtered request)
q.values(*vals_of_interest).annotate(f1=Case(...))
And it works fine, it displays the output f1
containing the correct values. However, when I try to add a larger number of elements to the annotation f1
, it simply fails (it does not throw an error, it just doesn’t result. For example
q.values(*vals_of_interest).annotate(f1=Case(...), f2=Sum('field_2'))
This conclusion simply does not have f1
anywhere. It shows the correct results f2
, but f1
simply does not exist. Is there a limit with Case
things like this in the annotation?
UPDATE: I was able to get both values to show by making f2
a Case
(only with default). This seems hacked and unnecessary, but at least shows the correct results. It would still be curious if there is a way without doing this
source
share