Django Admin interface for a Blog in 5 mins

By Nuno Mariz, on 13 June 2006 @ 21:16
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

Comments

  • #1 By Jeff Croft on 14 June 2006 @ 14:49
    Nice -- and it can be even simpler if you use the built-in comments module instead of building your own! :)
  • #2 By Nuno Mariz on 14 June 2006 @ 17:38
    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 By alabama swinger on 4 November 2006 @ 14:08
    Nice — and it can be even simpler
Comments are closed.