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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Django
#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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/051.7d70f899ea9a396d2c9bd71fe6933f93%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

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

Django
#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>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.1b76b6f7ee37304341ab64e27024314e%40djangoproject.com.