diff options
| author | Adam Johnson <me@adamj.eu> | 2017-04-03 13:39:57 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-04-03 08:39:57 -0400 |
| commit | 7f8a924b45906a66aa3f562489550eacf2a622ed (patch) | |
| tree | 9fe74f68ca77a290fa67add1605a21ad9c2bfadd /docs/ref | |
| parent | 7170820b4ed1b348422fa1b9882bf8ffe8412570 (diff) | |
Refs #27834 -- Removed Value wrapping from StrIndex's substring param.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/models/database-functions.txt | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt index 21b6f897ac..53f70ef242 100644 --- a/docs/ref/models/database-functions.txt +++ b/docs/ref/models/database-functions.txt @@ -240,26 +240,29 @@ Usage example:: ``StrIndex`` ============ -.. class:: StrIndex(expression, substring, **extra) +.. class:: StrIndex(string, substring, **extra) .. versionadded:: 2.0 -Returns a positive integer corresponding to the 1-indexed position of the -first occurrence of ``substring`` inside another string, or 0 if the substring -is not found. +Returns a positive integer corresponding to the 1-indexed position of the first +occurrence of ``substring`` inside ``string``, or 0 if ``substring`` is not +found. Usage example:: + >>> from django.db.models import Value as V >>> from django.db.models.functions import StrIndex >>> Author.objects.create(name='Margaret Smith') >>> Author.objects.create(name='Smith, Margaret') >>> Author.objects.create(name='Margaret Jackson') >>> authors = Author.objects.annotate( - ... smith_index=StrIndex('name', 'Smith')).order_by('smith_index') + ... smith_index=StrIndex('name', V('Smith')) + ... ).order_by('smith_index') >>> authors.first().smith_index 0 >>> authors = Author.objects.annotate( - ... smith_index=StrIndex('name', 'Smith')).filter(smith_index__gt=0) + ... smith_index=StrIndex('name', V('Smith')) + ... ).filter(smith_index__gt=0) <QuerySet [<Author: Margaret Smith>, <Author: Smith, Margaret>]> .. warning:: |
