I've come across a weird behavior, just wondering if it is a bug or a
feature.
My task is to group a list of actions by user, count the values sum
and filter them by absolute value. E.g.
user1 5
user1 10
user2 2
user3 -12
and limit = 10, I want to see
user1 15
user3 -12
Here's the snippet of my code:
Actions.objects.values("context_user").annotate(points =
Sum("value")).filter(Q(points__gt = limit) | Q(points__lt = -limit))
Note using OR in a filter. But to my surprise the SQL query looks
like:
... GROUP BY "action"."context_user_id" HAVING (SUM("action"."value")
> 0 AND SUM("action"."value") < 0 )
Somehow Django uses AND instead of OR, thus the result is always
empty.
Can anyone explain this behavior to me and point out the solution if
it's not a bug?
Thanks.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment