mirror of
https://github.com/django/django.git
synced 2025-11-25 21:22:14 +00:00
Fixed #29049 -- Added slicing notation to F expressions.
Co-authored-by: Priyansh Saxena <askpriyansh@gmail.com> Co-authored-by: Niclas Olofsson <n@niclasolofsson.se> Co-authored-by: David Smith <smithdc@gmail.com> Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com> Co-authored-by: Abhinav Yadav <abhinav.sny.2002@gmail.com>
This commit is contained in:
parent
561e16d6a7
commit
94b6f101f7
8 changed files with 256 additions and 4 deletions
|
|
@ -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()``
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue