changeset 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 5c0f9d80442e
children 66a3cafc4548
files bns_website/news/models.py bns_website/static/css/base.css bns_website/templates/news/news_list.html bns_website/templates/news/news_tag.html
diffstat 4 files changed, 18 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/bns_website/news/models.py	Sun Nov 06 21:16:22 2011 -0600
+++ b/bns_website/news/models.py	Sun Nov 06 22:13:27 2011 -0600
@@ -1,5 +1,6 @@
 from django.db import models
 from datetime import timedelta, datetime
+from django.core.urlresolvers import reverse
 
 # Create your models here.
 class News(models.Model):
@@ -11,19 +12,17 @@
     date = models.DateTimeField()
     content = models.TextField()
 
-    # User field?
-
+    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']
-
-    def __unicode__(self):
-        return self.title
--- a/bns_website/static/css/base.css	Sun Nov 06 21:16:22 2011 -0600
+++ b/bns_website/static/css/base.css	Sun Nov 06 22:13:27 2011 -0600
@@ -24,6 +24,6 @@
 li.review-list-item {
    margin-bottom: 30px;
 }
-#article {
+.article {
     margin-bottom: 1.5em;
 }
\ No newline at end of file
--- a/bns_website/templates/news/news_list.html	Sun Nov 06 21:16:22 2011 -0600
+++ b/bns_website/templates/news/news_list.html	Sun Nov 06 22:13:27 2011 -0600
@@ -7,10 +7,17 @@
 <h1>News</h1>
 <dl>
 {% for news in object_list %}
-<article id="article"><h2>{{ news.title }} {% if news.is_new %}<span class="label success">New</span>{% endif %}</h2>
-    <div>{{ news.content|safe }}</div>
-    <small><b>{{ news.date }}</b></small>
+<aside id="news{{news.id}}">
+<article class="article">
+    <header>
+        <h3>{{ news.title }} {% if news.is_new %}<span class="label success">New</span>{% endif %}</h3>
+    </header>
+    <section>
+        <p>{{ news.content|safe }}</p>
+        <small><b>{{ news.date }}</b></small>
+    </section>
 </article>
+</aside>
 
 {% endfor %}
 </dl>
--- a/bns_website/templates/news/news_tag.html	Sun Nov 06 21:16:22 2011 -0600
+++ b/bns_website/templates/news/news_tag.html	Sun Nov 06 22:13:27 2011 -0600
@@ -1,6 +1,6 @@
 {% load url from future %}
 <ul>
-{% for news in object_list %}
-  <li>{{ news.title }}</li>
+{% for item in object_list %}
+  <li><a href="{{ item.get_absolute_url }}">{{ item.title }}</a></li>
 {% endfor %}
 </ul>