From 7faf25d682b8e8f4fd2006eb7dfc71ed2a2193b7 Mon Sep 17 00:00:00 2001 From: Alokik Vijay Date: Sat, 9 Jul 2022 23:04:53 +0530 Subject: [PATCH] Fixed #30711 -- Doc'd django.contrib.postgres.fields.hstore.KeyTransform(). --- docs/ref/contrib/postgres/fields.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/ref/contrib/postgres/fields.txt b/docs/ref/contrib/postgres/fields.txt index d460cecc70..2185804f8d 100644 --- a/docs/ref/contrib/postgres/fields.txt +++ b/docs/ref/contrib/postgres/fields.txt @@ -319,6 +319,22 @@ 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`` ------------------------