Source

lindyjam / blog / models.py

Full commit
from django.db import models
from django.contrib.auth.models import User
import datetime

class Entry(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField()
    pub_date = models.DateTimeField('Date Published', default=datetime.datetime.now)
    body = models.TextField()
    author = models.ForeignKey(User)
    published = models.BooleanField(default=False)
    
    @models.permalink
    def get_absolute_url(self):
        return ('blog-entry', (self.pub_date.year, self.pub_date.month, 
                               self.pub_date.day, self.slug),)
    
    def __unicode__(self):
        return u'%s' % (self.title,)
    
    def snippet(self):
        return self.body[:50] + ('...' if len(self.body) > 50 else '')
    

class Comment(models.Model):
    name = models.CharField('Commenter', blank=False, null=False, max_length=40)
    body = models.TextField('Comment', blank=False, null=False)
    submitted = models.DateTimeField(default=datetime.datetime.now)
    entry = models.ForeignKey(Entry)
    
    def get_absolute_url(self):
        return self.entry.get_absolute_url() + "#comment-" + str(self.id)
    
    def __unicode__(self):
        return u'%s on %s' % (self.name, self.entry.title)
    
    def snippet(self):
        return self.body[:50] + ('...' if len(self.body) > 50 else '')