Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7285: Improved inspectdb handling of dashes in table and field…

… names. Thanks to redalastor@gmail.com for the report and Justin Bronn for the first part of a fix.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8404 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 77c949289e8cc93df47997c44b8710217996cf63 1 parent eab705f
Russell Keith-Magee authored August 16, 2008
15  django/core/management/commands/inspectdb.py
@@ -16,7 +16,7 @@ def handle_inspection(self):
16 16
         from django.db import connection
17 17
         import keyword
18 18
 
19  
-        table2model = lambda table_name: table_name.title().replace('_', '').replace(' ', '')
  19
+        table2model = lambda table_name: table_name.title().replace('_', '').replace(' ', '').replace('-', '')
20 20
 
21 21
         cursor = connection.cursor()
22 22
         yield "# This is an auto-generated Django model module."
@@ -45,12 +45,19 @@ def handle_inspection(self):
45 45
                 comment_notes = [] # Holds Field notes, to be displayed in a Python comment.
46 46
                 extra_params = {}  # Holds Field parameters such as 'db_column'.
47 47
 
48  
-                if ' ' in att_name:
  48
+                # If we need to do field name modifiations, 
  49
+                # remember the original field name
  50
+                if ' ' in att_name or '-' in att_name or keyword.iskeyword(att_name):
49 51
                     extra_params['db_column'] = att_name
50  
-                    att_name = att_name.replace(' ', '')
  52
+                  
  53
+                # Now modify the field name to make it python compatible.  
  54
+                if ' ' in att_name:
  55
+                    att_name = att_name.replace(' ', '_')
51 56
                     comment_notes.append('Field renamed to remove spaces.')
  57
+                if '-' in att_name:
  58
+                    att_name = att_name.replace('-', '_')
  59
+                    comment_notes.append('Field renamed to remove dashes.')
52 60
                 if keyword.iskeyword(att_name):
53  
-                    extra_params['db_column'] = att_name
54 61
                     att_name += '_field'
55 62
                     comment_notes.append('Field renamed because it was a Python reserved word.')
56 63
 

0 notes on commit 77c9492

Please sign in to comment.
Something went wrong with that request. Please try again.