diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2011-01-24 14:58:05 +0000 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2011-01-24 14:58:05 +0000 |
| commit | bafe879188f3cd268f81e426bcdf4addc2d9a10a (patch) | |
| tree | 626fac6fb3970793eec1824bb19c84b2dcff5ff8 /django | |
| parent | 3f528e10d50ff7ba19a8a9e6cb2f9417a1e7f270 (diff) | |
Fixed 14796 -- Modified order of operations performed on field names by the inspectdb command so it doesn't generates model fields with names equal to Python keywords. Thanks pappjm at gmail dot com for the report and mmcnickle for the fix.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15296 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/management/commands/inspectdb.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py index e45f22c287..5f0e278c61 100644 --- a/django/core/management/commands/inspectdb.py +++ b/django/core/management/commands/inspectdb.py @@ -20,7 +20,7 @@ class Command(NoArgsCommand): def handle_noargs(self, **options): try: for line in self.handle_inspection(options): - print line + self.stdout.write("%s\n" % line) except NotImplementedError: raise CommandError("Database inspection isn't supported for the currently selected database backend.") @@ -66,12 +66,11 @@ class Command(NoArgsCommand): if ' ' in att_name: att_name = att_name.replace(' ', '_') comment_notes.append('Field renamed to remove spaces.') + if '-' in att_name: att_name = att_name.replace('-', '_') comment_notes.append('Field renamed to remove dashes.') - if keyword.iskeyword(att_name): - att_name += '_field' - comment_notes.append('Field renamed because it was a Python reserved word.') + if column_name != att_name: comment_notes.append('Field name made lowercase.') @@ -97,6 +96,10 @@ class Command(NoArgsCommand): extra_params['unique'] = True field_type += '(' + + if keyword.iskeyword(att_name): + att_name += '_field' + comment_notes.append('Field renamed because it was a Python reserved word.') # Don't output 'id = meta.AutoField(primary_key=True)', because # that's assumed if it doesn't exist. |
