Author: mtredinnick
Date: 2011-08-21 19:46:59 -0700 (Sun, 21 Aug 2011)
New Revision: 16641

Modified:
   django/trunk/django/core/management/commands/inspectdb.py
Log:
Teach inspectdb to handle SQL column names that are digits.

There's no accounting for taste in the way some people name columns,
apparently. Create a column with a name of "1" and inspectdb will still
produce valid Python code now. Fixed #16536. Thanks tereaom and
danodonovan.

Modified: django/trunk/django/core/management/commands/inspectdb.py
===================================================================
--- django/trunk/django/core/management/commands/inspectdb.py   2011-08-22 
02:03:50 UTC (rev 16640)
+++ django/trunk/django/core/management/commands/inspectdb.py   2011-08-22 
02:46:59 UTC (rev 16641)
@@ -101,6 +101,12 @@
                     att_name += '_field'
                     comment_notes.append('Field renamed because it was a 
Python reserved word.')
 
+                if att_name.isdigit():
+                    att_name = 'number_%d' % int(att_name)
+                    extra_params['db_column'] = unicode(column_name)
+                    comment_notes.append("Field renamed because it wasn't a "
+                        "valid Python identifier.")
+
                 # Don't output 'id = meta.AutoField(primary_key=True)', because
                 # that's assumed if it doesn't exist.
                 if att_name == 'id' and field_type == 'AutoField(' and 
extra_params == {'primary_key': True}:

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to