[2.0.x] Fixed #29307 -- Fixed inspectdb import paths for django.contrib.postgres fields.

Thanks erindy for the report.

Backport of 65c44a5c1d from master
This commit is contained in:
Alasdair Nicol 2018-04-09 16:46:31 +00:00 committed by Tim Graham
parent f185a1fca0
commit 0eb71b85bf
3 changed files with 14 additions and 13 deletions

View File

@ -17,12 +17,12 @@ class PostgresConfig(AppConfig):
for conn in connections.all():
if conn.vendor == 'postgresql':
conn.introspection.data_types_reverse.update({
3802: 'django.contrib.postgresql.fields.JSONField',
3904: 'django.contrib.postgresql.fields.IntegerRangeField',
3906: 'django.contrib.postgresql.fields.FloatRangeField',
3910: 'django.contrib.postgresql.fields.DateTimeRangeField',
3912: 'django.contrib.postgresql.fields.DateRangeField',
3926: 'django.contrib.postgresql.fields.BigIntegerRangeField',
3802: 'django.contrib.postgres.fields.JSONField',
3904: 'django.contrib.postgres.fields.IntegerRangeField',
3906: 'django.contrib.postgres.fields.FloatRangeField',
3910: 'django.contrib.postgres.fields.DateTimeRangeField',
3912: 'django.contrib.postgres.fields.DateRangeField',
3926: 'django.contrib.postgres.fields.BigIntegerRangeField',
})
if conn.connection is not None:
register_type_handlers(conn)

View File

@ -9,4 +9,5 @@ Django 2.0.5 fixes several bugs in 2.0.4.
Bugfixes
========
* ...
* Corrected the import paths that ``inspectdb`` generates for
``django.contrib.postgres`` fields (:ticket:`29307`).

View File

@ -24,17 +24,17 @@ class InspectDBTests(PostgreSQLTestCase):
def test_json_field(self):
self.assertFieldsInModel(
'postgres_tests_jsonmodel',
['field = django.contrib.postgresql.fields.JSONField(blank=True, null=True)'],
['field = django.contrib.postgres.fields.JSONField(blank=True, null=True)'],
)
def test_range_fields(self):
self.assertFieldsInModel(
'postgres_tests_rangesmodel',
[
'ints = django.contrib.postgresql.fields.IntegerRangeField(blank=True, null=True)',
'bigints = django.contrib.postgresql.fields.BigIntegerRangeField(blank=True, null=True)',
'floats = django.contrib.postgresql.fields.FloatRangeField(blank=True, null=True)',
'timestamps = django.contrib.postgresql.fields.DateTimeRangeField(blank=True, null=True)',
'dates = django.contrib.postgresql.fields.DateRangeField(blank=True, null=True)',
'ints = django.contrib.postgres.fields.IntegerRangeField(blank=True, null=True)',
'bigints = django.contrib.postgres.fields.BigIntegerRangeField(blank=True, null=True)',
'floats = django.contrib.postgres.fields.FloatRangeField(blank=True, null=True)',
'timestamps = django.contrib.postgres.fields.DateTimeRangeField(blank=True, null=True)',
'dates = django.contrib.postgres.fields.DateRangeField(blank=True, null=True)',
],
)