summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMads Jensen <mje@inducks.org>2017-11-14 22:51:51 +0100
committerTim Graham <timograham@gmail.com>2017-11-29 10:40:01 -0500
commit4d3b8e199ec00a0aba111637a25f5abcaf3d6dfc (patch)
treea07340cb704486ebbbfecadaae2038599cfc566b /django
parentae4132a940486c86364bae71b92b7e95d62cc4a7 (diff)
[2.0.x] Fixed #28702 -- Made query lookups for CIText fields use citext.
Backport of f0a68c25118786d47041d0a435b2afa953be3c86 from master
Diffstat (limited to 'django')
-rw-r--r--django/contrib/postgres/fields/citext.py4
-rw-r--r--django/db/backends/postgresql/operations.py2
-rw-r--r--django/db/backends/postgresql/schema.py7
3 files changed, 10 insertions, 3 deletions
diff --git a/django/contrib/postgres/fields/citext.py b/django/contrib/postgres/fields/citext.py
index 42660001ae..46f6d3d1c2 100644
--- a/django/contrib/postgres/fields/citext.py
+++ b/django/contrib/postgres/fields/citext.py
@@ -4,6 +4,10 @@ __all__ = ['CICharField', 'CIEmailField', 'CIText', 'CITextField']
class CIText:
+
+ def get_internal_type(self):
+ return 'CI' + super().get_internal_type()
+
def db_type(self, connection):
return 'citext'
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index 268fa99b51..c4a61f7070 100644
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -77,6 +77,8 @@ class DatabaseOperations(BaseDatabaseOperations):
'istartswith', 'endswith', 'iendswith', 'regex', 'iregex'):
if internal_type in ('IPAddressField', 'GenericIPAddressField'):
lookup = "HOST(%s)"
+ elif internal_type in ('CICharField', 'CIEmailField', 'CITextField'):
+ lookup = '%s::citext'
else:
lookup = "%s::text"
diff --git a/django/db/backends/postgresql/schema.py b/django/db/backends/postgresql/schema.py
index 20cea3f249..18388cc523 100644
--- a/django/db/backends/postgresql/schema.py
+++ b/django/db/backends/postgresql/schema.py
@@ -107,11 +107,12 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
def _alter_field(self, model, old_field, new_field, old_type, new_type,
old_db_params, new_db_params, strict=False):
- # Drop indexes on varchar/text columns that are changing to a different
- # type.
+ # Drop indexes on varchar/text/citext columns that are changing to a
+ # different type.
if (old_field.db_index or old_field.unique) and (
(old_type.startswith('varchar') and not new_type.startswith('varchar')) or
- (old_type.startswith('text') and not new_type.startswith('text'))
+ (old_type.startswith('text') and not new_type.startswith('text')) or
+ (old_type.startswith('citext') and not new_type.startswith('citext'))
):
index_name = self._create_index_name(model._meta.db_table, [old_field.column], suffix='_like')
self.execute(self._delete_constraint_sql(self.sql_delete_index, model, index_name))