Refs #28643 -- Added LTrim, RTrim, and Trim database functions.

Thanks Tim Graham and Mads Jensen for reviews.
This commit is contained in:
Mariusz Felisiak 2018-03-15 20:57:23 +01:00 committed by GitHub
parent 47bb3b68ff
commit 9421aee35e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 104 additions and 7 deletions

View file

@ -800,6 +800,16 @@ Usage example::
>>> print(author.name_lower)
margaret smith
``LTrim``
---------
.. class:: LTrim(expression, **extra)
.. versionadded:: 2.1
Similar to :class:`~django.db.models.functions.Trim`, but removes only leading
spaces.
``Ord``
-------
@ -862,6 +872,16 @@ Usage example::
>>> print(author.last_letter)
h
``RTrim``
---------
.. class:: RTrim(expression, **extra)
.. versionadded:: 2.1
Similar to :class:`~django.db.models.functions.Trim`, but removes only trailing
spaces.
``StrIndex``
------------
@ -915,6 +935,25 @@ Usage example::
>>> print(Author.objects.get(name='Margaret Smith').alias)
marga
``Trim``
--------
.. class:: Trim(expression, **extra)
.. versionadded:: 2.1
Returns the value of the given text field or expression with leading and
trailing spaces removed.
Usage example::
>>> from django.db.models.functions import Trim
>>> Author.objects.create(name=' John ', alias='j')
>>> Author.objects.update(name=Trim('name'))
1
>>> print(Author.objects.get(alias='j').name)
John
``Upper``
---------