diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2006-02-04 20:18:18 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2006-02-04 20:18:18 +0000 |
| commit | c59901a4679faff44844bffdf877dc859fd1351a (patch) | |
| tree | 75ffd5f829dc76558447df4189d5714d33efcbfc | |
| parent | 9423c4e4a886b373243811e08a40a031ae484772 (diff) | |
Improved 'inspectdb' handling of Python keywords from [2271] to use the 'keywords' module rather than hard-coding the list of keywords.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2272 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/core/management.py | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/django/core/management.py b/django/core/management.py index f13d80d767..5ea9539d25 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -562,13 +562,12 @@ def inspectdb(db_name): "Generator that introspects the tables in the given database name and returns a Django model, one line at a time." from django.core import db from django.conf import settings + import keyword def table2model(table_name): object_name = table_name.title().replace('_', '') return object_name.endswith('s') and object_name[:-1] or object_name - reserved_python_words = set(['and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while']) - settings.DATABASE_NAME = db_name cursor = db.db.cursor() yield "# This is an auto-generated Django model module." @@ -593,7 +592,7 @@ def inspectdb(db_name): comment_notes = [] # Holds Field notes, to be displayed in a Python comment. extra_params = {} # Holds Field parameters such as 'db_column'. - if column_name in reserved_python_words: + if keyword.iskeyword(column_name): extra_params['db_column'] = column_name column_name += '_field' comment_notes.append('Field renamed because it was a Python reserved word.') |
