Django Admin interface for a Blog in 5 mins

It’s so cool with Django:

from django.db import models
from django.contrib.auth.models import User

class Tag(models.Model):
    name = models.CharField(maxlength=200, core=True)

    class Admin:
        ordering = ['name']   

    def __str__(self):
        return self.name

PUBLICATION_CHOICES = (
    ('Draft', 'Draft'),
    ('Published', 'Published'),
)

class Post(models.Model):
    author = models.ForeignKey(User)
    title = models.CharField(maxlength=200)
    summary = models.TextField()
    body = models.TextField()
    created = models.DateTimeField(default=models.LazyDate())
    last_modified = models.DateTimeField(auto_now=True)
    enable_comments = models.BooleanField(default=True)
    tags = models.ManyToManyField(Tag)
    publication = models.CharField(maxlength=32, choices=PUBLICATION_CHOICES, radio_admin=True, default='Published')

    class Admin:
        ordering = ['-created']
        search_fields = ['title']
        list_display = ('title','author', 'created')
        list_filter = ('created','last_modified','enable_comments','publication', 'tags')

    def __str__(self):
        return self.title

class Comment(models.Model):
    post = models.ForeignKey(Post)
    name = models.CharField(maxlength=100)
    email = models.EmailField()
    website = models.CharField(maxlength=200, blank=True, null=True)
    comment = models.TextField()
    created = models.DateTimeField(auto_now_add=True)
    last_modified = models.DateTimeField(auto_now=True)

    class Admin:
        ordering = ['-created']
        search_fields = ['name']
        list_display = ('post','name', 'created')
        list_filter = ('created','last_modified')

    def __str__(self):
        return self.name

3 Comments so far

  1. Jeff Croft on June 14th, 2006

    Nice — and it can be even simpler if you use the built-in comments module instead of building your own! :)

  2. Nuno Mariz on June 14th, 2006

    I only started to read the tutorials. Soon I will be there. ;)
    Yesterday, I’ve downloaded your LOST-theories.com. I’m going to take a deeper look on it.

  3. alabama swinger on November 4th, 2006

    Nice — and it can be even simpler

Leave a reply

You must be logged in to post a comment.