mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Made inspectdb tests deal with a smaller generated models.py file.
Implemented this by adding a stealth table_name_filter option for the command.
This commit is contained in:
@@ -26,6 +26,8 @@ class Command(NoArgsCommand):
|
||||
|
||||
def handle_inspection(self, options):
|
||||
connection = connections[options.get('database')]
|
||||
# 'table_name_filter' is a stealth option
|
||||
table_name_filter = options.get('table_name_filter')
|
||||
|
||||
table2model = lambda table_name: table_name.title().replace('_', '').replace(' ', '').replace('-', '')
|
||||
|
||||
@@ -43,6 +45,9 @@ class Command(NoArgsCommand):
|
||||
yield ''
|
||||
known_models = []
|
||||
for table_name in connection.introspection.table_names(cursor):
|
||||
if table_name_filter is not None and callable(table_name_filter):
|
||||
if not table_name_filter(table_name):
|
||||
continue
|
||||
yield 'class %s(models.Model):' % table2model(table_name)
|
||||
known_models.append(table2model(table_name))
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user