Login

Snippets by atombrella

Snippet List

aggregate filter

Makes it possible to add a filtering condition directly after the aggregate function (or possible, `aggregate(expression) WITHIN GROUP (ordering clause)`. This is mostly useful if the annotation has two or more expressions, so it's possible to compare the result with and without the applied filter; it's more compact than using `Case`. It's suggested to add `values` to the queryset to get a proper group by. Usage example: `books = Book.objects.values('publisher__name').annotate( count=Count('*'), filtercount=Filter(expression=Count('publisher__name'), condition=Q(rating__gte=5)) ) ` Supported on Postgresql 9.4+. Possible other third-party backends.

  • filter
  • postgresql
  • olap
  • aggregate
  • expression
Read More

replace

Small example of how to write your own function. This is not available in Django. The function just replaces static text strings, regular expressions are not supported. The syntax is the same in SQLite, PostgreSQL, MySQL and Oracle.

  • text
  • replace
Read More

atombrella has posted 2 snippets.