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 file.

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

from s2.portfolio.models import News
from django.contrib import admin

class NewsAdmin(admin.ModelAdmin):

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

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!

Things to come

A bit of a taster really, a post about the things that I intend to write – well that’s one way of getting me to ensure that I do write them.

I’ve written a helper to generate nested UL’s from the results of a find(‘threaded’) call. I’ve been using the helper to generate the nested lists for CSS menus and it is also great for sitemaps. Just needs a bit of tidying up before I set it free.

Back to basics with Auth
(This one is actually in draft right now) Another CakePHP one – I’ve been using a quite complex auth / groups / users solution derived the fabulous solution by Studio Canaria but these things get more and more complex. Recently for a project I just needed something simple but I’d forgotten how complex and powerful even basic Auth can be, so I decided to write a kind of back to basics tutorial.

My perfect E-book
I love books. I hate reading PDFs or anything book-like of the screen. My thoughts on the perfect E-book reader.