From 63300f7e686c2c452763cb512df9abf7734fd588 Mon Sep 17 00:00:00 2001 From: Tom Carrick Date: Sat, 8 Aug 2020 13:37:06 +0200 Subject: Fixed #21181 -- Added Collate database function. Thanks Simon Charette for reviews. --- docs/ref/models/database-functions.txt | 19 +++++++++++++++++++ docs/releases/3.2.txt | 3 +++ 2 files changed, 22 insertions(+) (limited to 'docs') diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt index da67d9e362..f5efdb7e87 100644 --- a/docs/ref/models/database-functions.txt +++ b/docs/ref/models/database-functions.txt @@ -87,6 +87,25 @@ Usage examples:: >>> now = timezone.now() >>> Coalesce('updated', Cast(now, DateTimeField())) +``Collate`` +----------- + +.. class:: Collate(expression, collation) + +.. versionadded:: 3.2 + +Takes an expression and a collation name to query against. + +For example, to filter case-insensitively in SQLite:: + + >>> Author.objects.filter(name=Collate(Value('john'), 'nocase')) + , ]> + +It can also be used when ordering, for example with PostgreSQL:: + + >>> Author.objects.order_by(Collate('name', 'et-x-icu')) + , , ]> + ``Greatest`` ------------ diff --git a/docs/releases/3.2.txt b/docs/releases/3.2.txt index 23b687f593..41929172c6 100644 --- a/docs/releases/3.2.txt +++ b/docs/releases/3.2.txt @@ -273,6 +273,9 @@ Models expressions that don't need to be selected but are used for filtering, ordering, or as a part of complex expressions. +* The new :class:`~django.db.models.functions.Collate` function allows + filtering and ordering by specified database collations. + Pagination ~~~~~~~~~~ -- cgit v1.3