Thursday, September 21, 2017

Re: Mixing Q objects and lookups with When conditionals

Hi Simon,

That's how I feel about it too, but couldn't find anything specifically related to it, thus prompting my question.

I basically fell into this because django lookups can't handle exclusion (NOT).  I suspect there's an alternative to use exclude before the aggregation, like 

SomeModel.objects.exclude(some_field__icontains = 'value').aggregate(total = Count(Case(When(field_two = 2, field_three = True, then = 1), output_field = IntegerField()))

but that's not exactly intuitive, and I ended up chaining Q expressions for the same result.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/749774a9-f89a-4d9d-be60-8e3c44e2bfe7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment