From 7f8a924b45906a66aa3f562489550eacf2a622ed Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 3 Apr 2017 13:39:57 +0100 Subject: Refs #27834 -- Removed Value wrapping from StrIndex's substring param. --- docs/ref/models/database-functions.txt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'docs/ref/models') 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) , ]> .. warning:: -- cgit v1.3