comparison 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
comparison
equal deleted inserted replaced
40:5c0f9d80442e 41:9ce9f77d6cde
1 from django.db import models 1 from django.db import models
2 from datetime import timedelta, datetime 2 from datetime import timedelta, datetime
3 from django.core.urlresolvers import reverse
3 4
4 # Create your models here. 5 # Create your models here.
5 class News(models.Model): 6 class News(models.Model):
6 """ 7 """
7 This model represents all the info we store about each news entry. 8 This model represents all the info we store about each news entry.
9 """ 10 """
10 title = models.CharField(max_length=128) 11 title = models.CharField(max_length=128)
11 date = models.DateTimeField() 12 date = models.DateTimeField()
12 content = models.TextField() 13 content = models.TextField()
13 14
14 # User field? 15 def __unicode__(self):
15 16 return self.title
16 17
17 def is_new(self): 18 def is_new(self):
18 if datetime.now() - self.date <= timedelta(days=30): 19 if datetime.now() - self.date <= timedelta(days=30):
19 return True 20 return True
20
21 return False 21 return False
22 22
23 def get_absolute_url(self):
24 return reverse('news') + '#news%d' % self.id
23 25
24 class Meta: 26 class Meta:
25 verbose_name_plural="News" 27 verbose_name_plural="News"
26 ordering = ['-date'] 28 ordering = ['-date']
27
28 def __unicode__(self):
29 return self.title