Flirting with Django – part 3 – setting plural model names in admin

This is probably a bit obvious to any experienced Django user, but it took me a bit of digging to find.

In Django when you create a model to use the automatic admin interface you have to add it to the admin.py file.

Here is an example which only includes a ‘news’ model:

1
2
3
4
5
6
7
8
 
from s2.portfolio.models import News
from django.contrib import admin
 
class NewsAdmin(admin.ModelAdmin):
    pass
 
admin.site.register(News)

The trouble is that it shows up in your Django admin interface as ‘Newss’ which is obviously a bit lame.

The answer is quite simple once you know how, you need to add ‘Meta’ information the model class (I believe this is an example of an ‘internal class’). The ‘Meta’ class contains information about each model such as the ordering with which records should be displayed in the admin etc. This is documented in the Django documentation here.

Example news model including the Meta information

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
class News(models.Model):
    title = models.CharField(max_length=200)
    summary = models.CharField(max_length=200)
    description = tinymce_models.HTMLField()
    slug = models.CharField(max_length=200)
    live = models.BooleanField(default=1)
    date = models.DateField()
 
    def __unicode__(self):
        return self.title
 
    class Meta:
        verbose_name_plural = 'News'

Like most things, easy when you know how!