﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31847	Adding table prefix stripping to inspectdb	François Poulain	nobody	"Hi,

I Plugged django on foreign db. It has tables prefixes. Stripping them from model name clarify the generated code and is welcome since the prefix isn't more meaningfull that the appname or the module name.

I did this as is:
{{{
--- a/base/management/commands/inspectdb.py
+++ b/base/management/commands/inspectdb.py
@@ -24,6 +24,10 @@ class Command(BaseCommand):
         parser.add_argument(
             '--include-partitions', action='store_true', help='Also output models for partition tables.',
         )
+        parser.add_argument(
+            '--tables-prefix', nargs='?', type=str, default='',
+            help='Tables prefix to be stripped from model names.',
+        )
         parser.add_argument(
             '--include-views', action='store_true', help='Also output models for database views.',
         )
@@ -40,7 +44,11 @@ class Command(BaseCommand):
         # 'table_name_filter' is a stealth option
         table_name_filter = options.get('table_name_filter')
 
+        tables_prefix = options['tables_prefix']
+
         def table2model(table_name):
+            if tables_prefix and table_name.startswith(tables_prefix):
+                table_name = table_name[len(tables_prefix):]
             return re.sub(r'[^a-zA-Z0-9]', '', table_name.title())
 
         with connection.cursor() as cursor:
}}}

How do you think about it?"	New feature	closed	Core (Management commands)	3.0	Normal	wontfix			Unreviewed	1	0	0	0	0	0
