mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Refs #28643 -- Added LTrim, RTrim, and Trim database functions.
Thanks Tim Graham and Mads Jensen for reviews.
This commit is contained in:
@@ -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``
|
||||
---------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user