Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Improved 'inspectdb' handling of Python keywords from [2271] to use t…

…he 'keywords' module rather than hard-coding the list of keywords.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 9423c4e commit c59901a4679faff44844bffdf877dc859fd1351a @adrianholovaty adrianholovaty committed
Showing with 2 additions and 3 deletions.
  1. +2 −3 django/core/
5 django/core/
@@ -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 table2model(table_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.')

0 comments on commit c59901a

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