Code

Ticket #16536: inspectdb_numeric_fields_16536.diff

File inspectdb_numeric_fields_16536.diff, 884 bytes (added by teraom, 3 years ago)
Line 
1Index: django/core/management/commands/inspectdb.py
2===================================================================
3--- django/core/management/commands/inspectdb.py        (revision 16578)
4+++ django/core/management/commands/inspectdb.py        (working copy)
5@@ -101,6 +101,11 @@
6                     att_name += '_field'
7                     comment_notes.append('Field renamed because it was a Python reserved word.')
8 
9+                if att_name.isdigit():
10+                    att_name = 'number_%d' % att_name
11+                    comment_notes.append('Field renamed because it wasn\'t a \
12+                    valid Python identifier')
13+
14                 # Don't output 'id = meta.AutoField(primary_key=True)', because
15                 # that's assumed if it doesn't exist.
16                 if att_name == 'id' and field_type == 'AutoField(' and extra_params == {'primary_key': True}: