diff options
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/models/expressions.txt | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/docs/ref/models/expressions.txt b/docs/ref/models/expressions.txt index 9d85442d9c..67baef7dfc 100644 --- a/docs/ref/models/expressions.txt +++ b/docs/ref/models/expressions.txt @@ -183,6 +183,28 @@ the field value of each one, and saving each one back to the database:: * getting the database, rather than Python, to do work * reducing the number of queries some operations require +.. _slicing-using-f: + +Slicing ``F()`` expressions +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. versionadded:: 5.1 + +For string-based fields, text-based fields, and +:class:`~django.contrib.postgres.fields.ArrayField`, you can use Python's +array-slicing syntax. The indices are 0-based and the ``step`` argument to +``slice`` is not supported. For example: + +.. code-block:: pycon + + >>> # Replacing a name with a substring of itself. + >>> writer = Writers.objects.get(name="Priyansh") + >>> writer.name = F("name")[1:5] + >>> writer.save() + >>> writer.refresh_from_db() + >>> writer.name + 'riya' + .. _avoiding-race-conditions-using-f: Avoiding race conditions using ``F()`` |
