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!

Win a signed print

To promote my free business listings directory, www.blinks.org.uk I have decided to give away a prize of a signed limited edition print of ‘Minibet’ (2005)

The 1000th business to register on the site will receive a copy, so register now.

Register with our free business directory for the chance to win a prize

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.

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

A nervy bit of sailing

dsc_2652.jpg

dsc_2653.jpg

dsc_2654.jpg

dsc_2655.jpg

Free UK Postcode Geocoding

I’ve just come across and started using a brilliant new free UK postcode lookup (so far it has provided me with the Latitude & Longitude of every postcode I’ve thrown at it), it’s fast, free and easy to use and can return the Latitude & Longitude as either CSV or JSON – whatever takes your fancy. Perhaps best of all, all it requires is the postcode, not other parts of the address like a property name or number.

http://www.ernestmarples.com (apparently Ernest Marples was the Postmaster general who introduced the postcode to the UK)