Opened 14 years ago
Closed 14 years ago
#17438 closed Bug (wontfix)
Model names wrong in administrator pages
| Reported by: | 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 )
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
Change History (2)
comment:1 by , 14 years ago
| Description: | modified (diff) | 
|---|
comment:2 by , 14 years ago
| Easy pickings: | unset | 
|---|---|
| Resolution: | → wontfix | 
| Status: | new → closed | 
  Note:
 See   TracTickets
 for help on using tickets.
    
That regex isn't about replacing underscores with spaces. As the comment above it mentions, the regex converts
InitialCapsto 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_namefor your models.