From cede5111bbeea1f02a7d35941a4264c7ff95df0a Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Mon, 19 Mar 2018 17:35:16 +0100 Subject: Refs #28643 -- Added LPad and RPad database functions. Thanks Tim Graham for the review. --- docs/ref/models/database-functions.txt | 31 +++++++++++++++++++++++++++++++ docs/releases/2.1.txt | 2 ++ 2 files changed, 33 insertions(+) (limited to 'docs') diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt index 9208a90574..2d0d5d2fe7 100644 --- a/docs/ref/models/database-functions.txt +++ b/docs/ref/models/database-functions.txt @@ -800,6 +800,27 @@ Usage example:: >>> print(author.name_lower) margaret smith +``LPad`` +-------- + +.. class:: LPad(expression, length, fill_text=Value(' '), **extra) + +.. versionadded:: 2.1 + +Returns the value of the given text field or expression padded on the left side +with ``fill_text`` so that the resulting value is ``length`` characters long. +The default ``fill_text`` is a space. + +Usage example:: + + >>> from django.db.models import Value + >>> from django.db.models.functions import LPad + >>> Author.objects.create(name='John', alias='j') + >>> Author.objects.update(name=LPad('name', 8, Value('abc'))) + 1 + >>> print(Author.objects.get(alias='j').name) + abcaJohn + ``LTrim`` --------- @@ -872,6 +893,16 @@ Usage example:: >>> print(author.last_letter) h +``RPad`` +-------- + +.. class:: RPad(expression, length, fill_text=Value(' '), **extra) + +.. versionadded:: 2.1 + +Similar to :class:`~django.db.models.functions.LPad`, but pads on the right +side. + ``RTrim`` --------- diff --git a/docs/releases/2.1.txt b/docs/releases/2.1.txt index 35261b2850..4d8a9a1d42 100644 --- a/docs/releases/2.1.txt +++ b/docs/releases/2.1.txt @@ -205,10 +205,12 @@ Models * A number of new text database functions are added: :class:`~django.db.models.functions.Chr`, :class:`~django.db.models.functions.Left`, + :class:`~django.db.models.functions.LPad`, :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.RPad`, :class:`~django.db.models.functions.RTrim`, and :class:`~django.db.models.functions.Trim`. -- cgit v1.3