Login

Tag "annotate"

Snippet List

Aggregation class "Count" with Case

Use it like below: totals = MyClass.aggregate( is_enabled_yes=CountCase('is_enabled', when=True), is_enabled_no=CountCase('is_enabled', when=False), count_if=CountCase('id', case="another_field in ('a','b')", when=True), )

  • count
  • annotate
  • aggregation
Read More

Aggregation class "Sum" with Case

Just use it like below: from downloaded_file import SumCase MyClass.objects.aggregate( sum1=SumCase('salary', case='salary < 4', when=True), sum1=SumCase('salary', case='type', when='director'), )

  • annotate
  • aggregation
  • sum
Read More

3 snippets posted so far.