summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-08-23 22:50:25 +0200
committerClaude Paroz <claude@2xlibre.net>2012-08-23 22:59:45 +0200
commitf5ea730dac0986b2d48889a2d0fab2c5befb4494 (patch)
tree702ba5cb7d2180c2d6b1209628c2397ff5aabf8e /django/core
parent395c6083af93cc37c7d16ef4db451091841cefdc (diff)
Fixed #18843 -- Replaced more special chars in column names (inspectdb)
Thanks airstrike for the report.
Diffstat (limited to 'django/core')
-rw-r--r--django/core/management/commands/inspectdb.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
index c3c0776273..936d5e89ab 100644
--- a/django/core/management/commands/inspectdb.py
+++ b/django/core/management/commands/inspectdb.py
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
import keyword
+import re
from optparse import make_option
from django.core.management.base import NoArgsCommand, CommandError
@@ -142,18 +143,16 @@ class Command(NoArgsCommand):
else:
field_params['db_column'] = col_name
- if ' ' in new_name:
- new_name = new_name.replace(' ', '_')
- field_notes.append('Field renamed to remove spaces.')
-
- if '-' in new_name:
- new_name = new_name.replace('-', '_')
- field_notes.append('Field renamed to remove dashes.')
+ new_name, num_repl = re.subn(r'\W', '_', new_name)
+ if num_repl > 0:
+ field_notes.append('Field renamed to remove unsuitable characters.')
if new_name.find('__') >= 0:
while new_name.find('__') >= 0:
new_name = new_name.replace('__', '_')
- field_notes.append("Field renamed because it contained more than one '_' in a row.")
+ if col_name.lower().find('__') >= 0:
+ # Only add the comment if the double underscore was in the original name
+ field_notes.append("Field renamed because it contained more than one '_' in a row.")
if new_name.startswith('_'):
new_name = 'field%s' % new_name