summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMads Jensen <mje@inducks.org>2018-01-18 02:46:15 +0100
committerTim Graham <timograham@gmail.com>2018-01-17 20:46:15 -0500
commit65728550bd6296871562da02069ddb86e9dd3482 (patch)
tree55fcab54194ea50d9ae7701b260fed80375e80e4 /docs
parentfcd431c6c3159a753f1cc0658cc4b25803ffccc1 (diff)
Refs #28643 -- Added Replace database function.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/database-functions.txt22
-rw-r--r--docs/releases/2.1.txt3
2 files changed, 25 insertions, 0 deletions
diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt
index acb22249c5..db708a6ce0 100644
--- a/docs/ref/models/database-functions.txt
+++ b/docs/ref/models/database-functions.txt
@@ -751,6 +751,28 @@ Usage example::
>>> print(author.name_lower)
margaret smith
+``Replace``
+~~~~~~~~~~~
+
+.. class:: Replace(expression, text, replacement=Value(''), **extra)
+
+.. versionadded:: 2.1
+
+Replaces all occurrences of ``text`` with ``replacement`` in ``expression``.
+The default replacement text is the empty string. The arguments to the function
+are case-sensitive.
+
+Usage example::
+
+ >>> from django.db.models import Value
+ >>> from django.db.models.functions import Replace
+ >>> Author.objects.create(name='Margaret Johnson')
+ >>> Author.objects.create(name='Margaret Smith')
+ >>> Author.objects.update(name=Replace('name', Value('Margaret'), Value('Margareth')))
+ 2
+ >>> Author.objects.values('name')
+ <QuerySet [{'name': 'Margareth Johnson'}, {'name': 'Margareth Smith'}]>
+
``StrIndex``
------------
diff --git a/docs/releases/2.1.txt b/docs/releases/2.1.txt
index f2141dbb99..b979ba2224 100644
--- a/docs/releases/2.1.txt
+++ b/docs/releases/2.1.txt
@@ -169,6 +169,9 @@ Models
* A ``BinaryField`` may now be set to ``editable=True`` if you wish to include
it in model forms.
+* The new :class:`~django.db.models.functions.Replace` database function
+ replaces strings in an expression.
+
Requests and Responses
~~~~~~~~~~~~~~~~~~~~~~