Opened 3 years ago

Closed 3 years ago

#32266 closed Cleanup/optimization (duplicate)

Inspectdb command shows ugly classnames from django-based tables

Reported by: Francisco Javier Lendínez Tirado Owned by: nobody
Component: Core (Management commands) Version: 3.1
Severity: Normal Keywords: inspectdb command
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Today I used the inspectdb command to test it. When it recovered the models, I see that class names are "ugly" when these models are default-created Django models.

For example:
Original model

class User(AbstractUser):
    # ...
    token = models.CharField(default=get_random_string, unique=True, max_length=20)

Generated model

class UsersUser(models.Model):
    token = models.CharField(unique=True, max_length=20)
   # ...

    class Meta:
        managed = False
        db_table = 'users_user'

UsersUser (or AppnameModel) could be counterintuitive, a simple flag --remove-appnames is enough to indicate that the first word could be removed (understanding that most of the app names are only a word).

Here we can check that the flag is active and remove the first word:
https://github.com/django/django/blob/master/django/core/management/commands/inspectdb.py#L43

This improvement seems trivial but is useful enough to take it into account because these table names need manual actions, avoiding sync models automatically between projects automatically (for example)

Change History (1)

comment:1 by Mariusz Felisiak, 3 years ago

Has patch: unset
Resolution: duplicate
Status: newclosed

Duplicate of #31847.

Note: See TracTickets for help on using tickets.
Back to Top