Code

Opened 2 years ago

Closed 2 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 gabrielhurley)

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

Bad line: django\db\models\options.py(20):

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

Fix:

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

Best regards,

Peter Szabady

Attachments (0)

Change History (2)

comment:1 Changed 2 years ago by gabrielhurley

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

comment:2 Changed 2 years ago by gabrielhurley

  • Easy pickings unset
  • Resolution set to wontfix
  • Status changed from new to closed

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.

Last edited 2 years ago by gabrielhurley (previous) (diff)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.