1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Refs #27834 -- Removed Value wrapping from StrIndex's substring param.

This commit is contained in:
Adam Johnson
2017-04-03 13:39:57 +01:00
committed by Tim Graham
parent 7170820b4e
commit 7f8a924b45
3 changed files with 22 additions and 21 deletions

View File

@@ -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::