Reverted "Fixed #30711 -- Doc'd django.contrib.postgres.fields.hstore.KeyTransform()."

This reverts commit 7faf25d682. The same
can be achieved with F() so there is no need to expose an extra API.
This commit is contained in:
Mariusz Felisiak 2022-08-31 22:12:30 +02:00 committed by GitHub
parent 838cc0f449
commit cb06f5ef8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 16 deletions

View File

@ -343,22 +343,6 @@ transform do not change. For example::
valid for a given field. This can be done using the valid for a given field. This can be done using the
:class:`~django.contrib.postgres.validators.KeysValidator`. :class:`~django.contrib.postgres.validators.KeysValidator`.
KeyTransform() expression
-------------------------
.. class:: hstore.KeyTransform(key_name, *args, **kwargs)
Returns the value of the given ``key_name``. This allows you to annotate a key
value. For example::
>>> from django.contrib.postgres.fields.hstore import KeyTransform
>>> Dog.objects.create(name="Rufus", data={"breed": "labrador"})
>>> Dog.objects.create(name="Meg", data={"breed": "collie", "owner": "Bob"})
>>> rufus = Dog.objects.annotate(breed=KeyTransform("breed", "data"))[0]
>>> rufus.breed
'labrador'
Querying ``HStoreField`` Querying ``HStoreField``
------------------------ ------------------------
@ -395,6 +379,13 @@ You can chain other lookups after key lookups::
>>> Dog.objects.filter(data__breed__contains='l') >>> Dog.objects.filter(data__breed__contains='l')
<QuerySet [<Dog: Rufus>, <Dog: Meg>]> <QuerySet [<Dog: Rufus>, <Dog: Meg>]>
or use ``F()`` expressions to annotate a key value. For example::
>>> from django.db.models import F
>>> rufus = Dog.objects.annotate(breed=F("data__breed"))[0]
>>> rufus.breed
'labrador'
If the key you wish to query by clashes with the name of another lookup, you If the key you wish to query by clashes with the name of another lookup, you
need to use the :lookup:`hstorefield.contains` lookup instead. need to use the :lookup:`hstorefield.contains` lookup instead.