annotate bns_website/news/models.py @ 23:1357c69e887d

- I added a little New badge for posts in the last 3 days. - I added a <div class=""> tag to the news posts to group them within the same Bootstrap CSS alert block. I'm not sure if it's a good idea or not, but it's kind of cool.
author Bob Mourlam <bob.mourlam@gmail.com>
date Mon, 31 Oct 2011 22:08:45 -0500
parents 687af3cb0525
children 353ca3874f43
rev   line source
bob@14 1 from django.db import models
bob@23 2 from datetime import timedelta, datetime
bob@14 3
bob@14 4 # Create your models here.
bob@14 5 class News(models.Model):
bob@14 6 """
bob@14 7 This model represents all the info we store about each news entry.
bob@14 8
bob@14 9 """
bob@14 10 title = models.CharField(max_length=128)
bob@14 11 date = models.DateTimeField()
bob@14 12 content = models.TextField()
bob@14 13
bob@14 14 # User field?
bob@14 15
bob@14 16
bob@23 17 def is_new(self):
bob@23 18 if datetime.now() - self.date <= timedelta(days=3):
bob@23 19 return True
bob@23 20
bob@23 21 return False
bob@23 22
bob@14 23
bob@14 24 class Meta:
bob@14 25 verbose_name_plural="News"
bob@21 26 ordering = ['-date']
bob@14 27
bob@14 28 def __unicode__(self):
bob@14 29 return self.title