#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.7d70f899ea9a396d2c9bd71fe6933f93%40djangoproject.com.

Reply via email to