In the same way that you can give fields and models verbose names that appear in the Django admin, can you give an app a custom name?
views:
2697answers:
7You can't give apps a custom name (at the moment at least; I believe this is going to be addressed at some point), but you can give your fields a
"display name" by passing the verbose_name
keyword argument to your fields (this is also conveniently the first positonal argument).
So, you can do either:
address = models.CharField(blank=False, max_length=250, verbose_name='Address (Line 1)')
or
address = models.CharField('Address (Line 1)', blank=False, max_length=250)
…and the admin will display these "pretty" versions instead.
I'm not sure if you're saying you know this already or not, but if not, you can give your models custom names too, also with the verbose_name
(and verbose_name_plural
) properties in the model's Meta
class, like:
class ModelName(models.Model):
# your model definition here
class Meta:
verbose_name = 'verbose model name'
verbose_name_plural = 'plural verbose model name'
You can override the __str__()
method for a model declaration:
from django.utils.encoding import smart_str
def __str__(self):
return smart_str("%s - %s" % (self.name, self.company))
Django uses that in the admin listings for that model.
Give them a verbose_name property.
Don't get your hopes up. You will also need to copy the index view from django.contrib.admin.sites into your own ProjectAdminSite view and include it in your own custom admin instance:
class ProjectAdminSite(AdminSite):
def index(self, request, extra_context=None):
copied stuff here...
admin.site = ProjectAdminSite()
then tweak the copied view so that it uses your verbose_name property as the label for the app.
I did it by adding something a bit like this to the copied view:
try:
app_name = model_admin.verbose_name
except AttributeError:
app_name = app_label
While you are tweaking the index view why not add an 'order' property too.
It would be nice to be able to set the applications verbose_name in either it's init.py or admin.py file. So the init.py file in your applications directory could look like:
class Meta:
verbose_name = 'My Django App'
Django 1.2 maybe?
You can give your application a custom name by defining app_label in your model definition. But as django builds the admin page it will hash models by their app_label, so if you want them to appear in one application, you have to define this name in all models of your application.
class MyModel(models.Model):
pass
class Meta:
app_label = 'My APP name'
Well I started an app called todo and have now decided I want it to be named Tasks. The problem is that I already have data within my table so my work around was as follows. Placed into the models.py:
class Meta:
app_label = 'Tasks'
db_table = 'mytodo_todo'
Hope it helps.