mirror of https://github.com/django/django.git
Fixed #21090 -- Allowed backends to provide dotted field path to inspectdb.
This commit is contained in:
parent
abb10db06f
commit
e61cc87129
|
@ -117,7 +117,12 @@ class Command(NoArgsCommand):
|
||||||
if not field_type in ('TextField(', 'CharField('):
|
if not field_type in ('TextField(', 'CharField('):
|
||||||
extra_params['null'] = True
|
extra_params['null'] = True
|
||||||
|
|
||||||
field_desc = '%s = models.%s' % (att_name, field_type)
|
field_desc = '%s = %s%s' % (
|
||||||
|
att_name,
|
||||||
|
# Custom fields will have a dotted path
|
||||||
|
'' if '.' in field_type else 'models.',
|
||||||
|
field_type,
|
||||||
|
)
|
||||||
if extra_params:
|
if extra_params:
|
||||||
if not field_desc.endswith('('):
|
if not field_desc.endswith('('):
|
||||||
field_desc += ', '
|
field_desc += ', '
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from unittest import expectedFailure
|
from unittest import expectedFailure, skipUnless
|
||||||
|
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
|
@ -162,3 +162,25 @@ class InspectDBTestCase(TestCase):
|
||||||
output = out.getvalue()
|
output = out.getvalue()
|
||||||
self.longMessage = False
|
self.longMessage = False
|
||||||
self.assertIn(" managed = False", output, msg='inspectdb should generate unmanaged models.')
|
self.assertIn(" managed = False", output, msg='inspectdb should generate unmanaged models.')
|
||||||
|
|
||||||
|
@skipUnless(connection.vendor == 'sqlite',
|
||||||
|
"Only patched sqlite's DatabaseIntrospection.data_types_reverse for this test")
|
||||||
|
def test_custom_fields(self):
|
||||||
|
"""
|
||||||
|
Introspection of columns with a custom field (#21090)
|
||||||
|
"""
|
||||||
|
out = StringIO()
|
||||||
|
orig_data_types_reverse = connection.introspection.data_types_reverse
|
||||||
|
try:
|
||||||
|
connection.introspection.data_types_reverse = {
|
||||||
|
'text': 'myfields.TextField',
|
||||||
|
'bigint': 'BigIntegerField',
|
||||||
|
}
|
||||||
|
call_command('inspectdb',
|
||||||
|
table_name_filter=lambda tn: tn.startswith('inspectdb_columntypes'),
|
||||||
|
stdout=out)
|
||||||
|
output = out.getvalue()
|
||||||
|
self.assertIn("text_field = myfields.TextField()", output)
|
||||||
|
self.assertIn("big_int_field = models.BigIntegerField()", output)
|
||||||
|
finally:
|
||||||
|
connection.introspection.data_types_reverse = orig_data_types_reverse
|
||||||
|
|
Loading…
Reference in New Issue