diff options
Diffstat (limited to 'docs/ref/models')
| -rw-r--r-- | docs/ref/models/database-functions.txt | 22 |
1 files changed, 22 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`` ------------ |
