bob@14: from django.db import models bob@23: from datetime import timedelta, datetime bob@41: from django.core.urlresolvers import reverse bob@14: bob@14: # Create your models here. bob@14: class News(models.Model): bob@14: """ bob@14: This model represents all the info we store about each news entry. bob@14: bob@14: """ bob@14: title = models.CharField(max_length=128) bob@14: date = models.DateTimeField() bob@14: content = models.TextField() bob@14: bob@41: def __unicode__(self): bob@41: return self.title bob@14: bob@23: def is_new(self): bob@37: if datetime.now() - self.date <= timedelta(days=30): bob@23: return True bob@23: return False bob@23: bob@41: def get_absolute_url(self): bob@41: return reverse('news') + '#news%d' % self.id bob@14: bob@14: class Meta: bob@14: verbose_name_plural="News" bob@21: ordering = ['-date']