view bns_website/news/models.py @ 41:9ce9f77d6cde

I added a get_absolute_url() to the news model so I can use that in the news template tag to create a link to the correct anchor on the news list page. The link works, but for some reason it goes to the beginning of the article content and not to the title. I've played around with the article tag and making an aside tag with an id and for whatever reason it always goes to the article content.
author Bob Mourlam <bob.mourlam@gmail.com>
date Sun, 06 Nov 2011 22:13:27 -0600
parents 353ca3874f43
children
line wrap: on
line source
from django.db import models
from datetime import timedelta, datetime
from django.core.urlresolvers import reverse

# Create your models here.
class News(models.Model):
    """
    This model represents all the info we store about each news entry.

    """
    title = models.CharField(max_length=128)
    date = models.DateTimeField()
    content = models.TextField()

    def __unicode__(self):
        return self.title

    def is_new(self):
        if datetime.now() - self.date <= timedelta(days=30):
            return True
        return False

    def get_absolute_url(self):
        return reverse('news') + '#news%d' % self.id

    class Meta:
        verbose_name_plural="News"
        ordering = ['-date']