mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16: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``
|
||||
---------
|
||||
|
||||
|
||||
@@ -204,10 +204,13 @@ Models
|
||||
|
||||
* A number of new text database functions are added:
|
||||
:class:`~django.db.models.functions.Chr`,
|
||||
:class:`~django.db.models.functions.Ord`,
|
||||
:class:`~django.db.models.functions.Left`,
|
||||
:class:`~django.db.models.functions.Right`, and
|
||||
:class:`~django.db.models.functions.Replace`.
|
||||
:class:`~django.db.models.functions.LTrim`,
|
||||
:class:`~django.db.models.functions.Ord`,
|
||||
:class:`~django.db.models.functions.Replace`,
|
||||
:class:`~django.db.models.functions.Right`,
|
||||
:class:`~django.db.models.functions.RTrim`, and
|
||||
:class:`~django.db.models.functions.Trim`.
|
||||
|
||||
* The new :class:`~django.db.models.functions.TruncWeek` function truncates
|
||||
:class:`~django.db.models.DateField` and
|
||||
|
||||
Reference in New Issue
Block a user