diff options
author | Dan McGee <dpmcgee@gmail.com> | 2011-02-18 10:00:33 -0600 |
---|---|---|
committer | Dan McGee <dpmcgee@gmail.com> | 2011-02-18 10:00:33 -0600 |
commit | 06f5639680ed2ec07b4472d027b63b0d406944c9 (patch) | |
tree | 3859a01176d2cf39e7682ae91b8739ddf5ed82fa | |
parent | 36931244ae2a0827844d39d30a856917dc7fd5b9 (diff) | |
download | website-06f5639680ed2ec07b4472d027b63b0d406944c9.tar.gz website-06f5639680ed2ec07b4472d027b63b0d406944c9.zip |
Add similar posts section to blog template
Signed-off-by: Dan McGee <dpmcgee@gmail.com>
-rw-r--r-- | blog/models.py | 5 | ||||
-rw-r--r-- | media/style-13.css (renamed from media/style-12.css) | 3 | ||||
-rw-r--r-- | templates/base.html | 2 | ||||
-rw-r--r-- | templates/blog/post_detail.html | 12 |
4 files changed, 21 insertions, 1 deletions
diff --git a/blog/models.py b/blog/models.py index ea64cef..8f203ac 100644 --- a/blog/models.py +++ b/blog/models.py @@ -48,6 +48,11 @@ class Post(models.Model): # categories? sure, why not. categories = models.ManyToManyField(PostCategory, verbose_name="categories") + def similar_posts(self): + return Post.objects.filter( + categories__in=self.categories.all()).exclude( + id=self.id).distinct().order_by('-pub_date') + def __unicode__(self): return self.title diff --git a/media/style-12.css b/media/style-13.css index a4ae32d..4dc894e 100644 --- a/media/style-12.css +++ b/media/style-13.css @@ -184,6 +184,9 @@ a:visited { color: #7c7c7c; } font-weight: bold; margin: 0.5em 0 0 0; } +.similar { + font-size:0.9em; +} .commentcount { font-size: 0.8em; font-weight: bold; diff --git a/templates/base.html b/templates/base.html index 3790ae1..9da78c6 100644 --- a/templates/base.html +++ b/templates/base.html @@ -4,7 +4,7 @@ <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=640" /> - <link rel="stylesheet" type="text/css" href="/media/style-12.css" /> + <link rel="stylesheet" type="text/css" href="/media/style-13.css" /> <title>{% block title %}toofishes.net{% endblock %}</title> {% block headdata %}{% endblock %} </head> diff --git a/templates/blog/post_detail.html b/templates/blog/post_detail.html index d9cce90..88b75a2 100644 --- a/templates/blog/post_detail.html +++ b/templates/blog/post_detail.html @@ -14,6 +14,18 @@ <span><a href="{% url blog-single-tag category=category %}">{{ category }}</a></span>{% endfor %} </div> </div> + {% if object.similar_posts %} + <div class="similar"> + <h3 class="similartitle">Similar Posts</h3> + <div class="similarposts"> + <ul> + {% for post in object.similar_posts|slice:":5" %} + <li><a href="{{ post.get_absolute_url }}">{{ post.title }}</a> - {{ post.pub_date|date }}</li> + {% endfor %} + </ul> + </div> + {% endif %} + </div> {% load comments %}{% get_comment_count for object as comment_count %}{% get_comment_list for object as comment_list %} <div class="comments"> <a name="comments" id="comments"></a> |