From 02876534aba63755e7418ee03a691ef6dcdb4416 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Wed, 31 Aug 2022 22:12:30 +0200 Subject: [PATCH] [4.1.x] Reverted "Fixed #30711 -- Doc'd django.contrib.postgres.fields.hstore.KeyTransform()." This reverts commit 7faf25d682b8e8f4fd2006eb7dfc71ed2a2193b7. The same can be achieved with F() so there is no need to expose an extra API. Backport of cb06f5ef8c80fc6a610db0fc36fb9dc7c625335a from main --- docs/ref/contrib/postgres/fields.txt | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/docs/ref/contrib/postgres/fields.txt b/docs/ref/contrib/postgres/fields.txt index 6757f81a18..4dc83d6a0d 100644 --- a/docs/ref/contrib/postgres/fields.txt +++ b/docs/ref/contrib/postgres/fields.txt @@ -321,22 +321,6 @@ transform do not change. For example:: valid for a given field. This can be done using the :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`` ------------------------ @@ -373,6 +357,13 @@ You can chain other lookups after key lookups:: >>> Dog.objects.filter(data__breed__contains='l') , ]> +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 need to use the :lookup:`hstorefield.contains` lookup instead.