Opened 5 years ago

Closed 5 years ago

#17438 closed Bug (wontfix)

Model names wrong in administrator pages

Reported by: pszabady@… Owned by: nobody
Component: Core (Other) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Gabriel Hurley)

If the model name is SERVER_CONFIG then "Server r_config" will be displayed in the admin interface.

Bad line: django\db\models\

get_verbose_name = lambda class_name: re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', class_name).lower().strip()

Reproduce in python prompt:

>>> import re
>>> e =  re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', "server_config").lower().strip()
>>> print e
>>> e =  re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', "SERVER_CONFIG").lower().strip()
>>> print e
serve r_config


get_verbose_name = lambda class_name: class_name.lower().replace("_"," ")

Best regards,

Peter Szabady

Change History (2)

comment:1 Changed 5 years ago by Gabriel Hurley

Description: modified (diff)
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 5 years ago by Gabriel Hurley

Easy pickings: unset
Resolution: wontfix
Status: newclosed

That regex isn't about replacing underscores with spaces. As the comment above it mentions, the regex converts InitialCaps to lowercase with spaces.

As per PEP8:

Class Names

      Almost without exception, class names use the CapWords convention.
      Classes for internal use have a leading underscore in addition.

Thus, models (as classes) in general should not be named in ALL_CAPS. By contrast ALL_CAPS is usually reserved for global variables/immutable values.

While I can see how that would be frustrating if your codebase has chosen a different convention, this doesn't look like a place to me where we need to change the default behavior. You can simply override verbose_name for your models.

Version 0, edited 5 years ago by Gabriel Hurley (next)
Note: See TracTickets for help on using tickets.
Back to Top