An example of when we might want to do this is when we want to create a
django package where a non-Django package already exists. e.g. Say we want
to create an admin interface for managing RSS feeds and call it
"djangofeeds" but there's already a Python package called "feeds". We'd
want the app_label to mirror the logical Python package name, but have it
appear in admin as simply "Feeds" for clarity.
Another example when this would be useful is for renaming of the aesthetic
appearance of an existing app without effecting the database. Currently,
if you change app_label on an app with existing data, this also changes
all the names of your tables, causing South migrations to delete your old
tables along with all your data.
A partial solution to this problem is to use a class that overrides
str.title, like:
{{{
class StringWithTitle(str):
"""
String class with a title method. Can be used to override
admin app names.
http://ionelmc.wordpress.com/2011/06/24/custom-app-names-in-the-
django-admin/
"""
def __new__(cls, value, title):
instance = str.__new__(cls, value)
instance._title = title
return instance
def title(self):
return self._title
__copy__ = lambda self: self
__deepcopy__ = lambda self, memodict: self
class MyModel(models.Model):
<columns>
class Meta:
app_label = StringWithTitle('my_app_label', 'My Fancy App
Label')
}}}
However, in order for this to work everywhere in admin, all renderings of
app_label would have to call title(). Unfortunately, admin renders
app_labels inconsistently. In many places it calls title() but in others
it calls capfirst().
If all renderings of app_label used title(), this would resolve the
problem, and it would be a very simple alternative solution to ticket
https://code.djangoproject.com/ticket/3591.
--
Ticket URL: <https://code.djangoproject.com/ticket/21622>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Submitted pull request https://github.com/django/django/pull/2080
implementing this change.
--
Ticket URL: <https://code.djangoproject.com/ticket/21622#comment:1>
* status: new => closed
* resolution: => duplicate
Comment:
Duplicate of #3591 - which is once again being actively worked on again
with a more narrow focus just a few things - this being one of main ones.
--
Ticket URL: <https://code.djangoproject.com/ticket/21622#comment:2>