[Django] #31847: Adding table prefix stripping to inspectdb

6 views
Skip to first unread message

Django

unread,
Aug 1, 2020, 10:03:04 AM8/1/20
to django-...@googlegroups.com
#31847: Adding table prefix stripping to inspectdb
-------------------------------------+-------------------------------------
Reporter: François | Owner: nobody
Poulain |
Type: New | Status: new
feature |
Component: Core | Version: 3.0
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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?

--
Ticket URL: <https://code.djangoproject.com/ticket/31847>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 4, 2020, 4:38:48 AM8/4/20
to django-...@googlegroups.com
#31847: Adding table prefix stripping to inspectdb
-------------------------------------+-------------------------------------
Reporter: François Poulain | Owner: nobody
Type: New feature | Status: closed
Component: Core (Management | Version: 3.0
commands) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => wontfix


Comment:

Thanks for the suggestion.

I don't think this is worth the complexity. You're meant to edit the
models files `inspectdb` generates. It's just not worth us going down the
path of adding various code paths to make small tweaks in the generation:
better to do that in the editor.

--
Ticket URL: <https://code.djangoproject.com/ticket/31847#comment:1>

Reply all
Reply to author
Forward
0 new messages