Missing annotate entry in django when using Case

I am trying to do some work like aggregation on a model in django using annotateandCase

So, I have something like the following ( qalready filtered request)

q.values(*vals_of_interest).annotate(f1=Case(...))

And it works fine, it displays the output f1containing 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 f1anywhere. It shows the correct results f2, but f1simply does not exist. Is there a limit with Casethings like this in the annotation?

UPDATE: I was able to get both values ​​to show by making f2a 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

+4
source share

Source: https://habr.com/ru/post/1613523/


All Articles