Okay, okay, names can be two letters.
author |
Steve Losh <steve@stevelosh.com> |
date |
Wed, 16 Sep 2009 20:39:07 -0400 |
parents |
8c03bf5d3f9f |
children |
87dafa5e8959 |
from django.db import models
import datetime
class Entry(models.Model):
title = models.CharField(max_length=140)
snip = models.CharField(max_length=140)
slug = models.SlugField()
pub_date = models.DateTimeField('Date Published',
default=datetime.datetime.now)
body = models.TextField()
published = models.BooleanField(default=False)
class Meta:
verbose_name = 'entry'
verbose_name_plural = 'entries'
@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,)
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)
spam = models.BooleanField(default=False)
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 snip(self):
return self.body[:40] + ('...' if len(self.body) > 40 else '')