SomeModel.objects.aggregate(total = Count(Case(When(~Q(some_field__icontains = 'value'), field_two = 2, field_three = True, then = 1), output_field = IntegerField()))
/home/jason/.virtualenvs/work/lib/python2.7/site-packages/django/db/models/expressions.pyc in __init__(self, condition, then, **lookups) 687 condition, lookups = Q(**lookups), None 688 if condition is None or not isinstance(condition, Q) or lookups:--> 689 raise TypeError("__init__() takes either a Q object or lookups as keyword arguments") 690 super(When, self).__init__(output_field=None) 691 self.condition = condition
TypeError: __init__() takes either a Q object or lookups as keyword arguments
query = ~Q(some_field__icontains = 'value') & Q(field_two = 2) & Q(field_three = True)
SomeModel.objects.aggregate(total = Count(Case(When(query, then = 1), output_field = IntegerField()))
__init__() takes either a Q object or lookups as keyword arguments
SomeModel.objects.exclude(some_field__icontains = 'value').aggregate(total = Count(Case(When(field_two = 2, field_three = True, then = 1), output_field = IntegerField()))