diff --git a/django/contrib/postgres/fields/jsonb.py b/django/contrib/postgres/fields/jsonb.py index b4574cc5aa..c195394409 100644 --- a/django/contrib/postgres/fields/jsonb.py +++ b/django/contrib/postgres/fields/jsonb.py @@ -133,6 +133,10 @@ class KeyTransformTextLookupMixin(object): super(KeyTransformTextLookupMixin, self).__init__(key_text_transform, *args, **kwargs) +class KeyTransformIExact(KeyTransformTextLookupMixin, builtin_lookups.IExact): + pass + + class KeyTransformIContains(KeyTransformTextLookupMixin, builtin_lookups.IContains): pass @@ -161,6 +165,7 @@ class KeyTransformIRegex(KeyTransformTextLookupMixin, builtin_lookups.IRegex): pass +KeyTransform.register_lookup(KeyTransformIExact) KeyTransform.register_lookup(KeyTransformIContains) KeyTransform.register_lookup(KeyTransformStartsWith) KeyTransform.register_lookup(KeyTransformIStartsWith) diff --git a/tests/postgres_tests/test_json.py b/tests/postgres_tests/test_json.py index 9691329a49..4e8851d485 100644 --- a/tests/postgres_tests/test_json.py +++ b/tests/postgres_tests/test_json.py @@ -238,6 +238,10 @@ class TestQuerying(PostgreSQLTestCase): self.objs[7:9] ) + def test_iexact(self): + self.assertTrue(JSONModel.objects.filter(field__foo__iexact='BaR').exists()) + self.assertFalse(JSONModel.objects.filter(field__foo__iexact='"BaR"').exists()) + def test_icontains(self): self.assertFalse(JSONModel.objects.filter(field__foo__icontains='"bar"').exists())