From a7c649d5c17d20680ff04be9d5100548d8cda2a3 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sun, 22 Jun 2014 15:11:40 +0000 Subject: [PATCH] Add get_post_relative_link template tag to generate relative links to blog posts --- blog/templatetags/blog_link.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/blog/templatetags/blog_link.py b/blog/templatetags/blog_link.py index df3bc13..4c86a82 100644 --- a/blog/templatetags/blog_link.py +++ b/blog/templatetags/blog_link.py @@ -1,8 +1,15 @@ from django import template from django.core.urlresolvers import reverse +from django.conf import settings +import pytz register = template.Library() +@register.simple_tag +def get_post_relative_link(post): + post_date = post.created_at.astimezone(pytz.timezone(settings.TIME_ZONE)) + return reverse('blog:read', args=(post_date.year, post_date.month, post_date.day, post.slug)) + @register.simple_tag(takes_context = True) def get_post_link(context, post): return context['request'].build_absolute_uri(reverse('blog:read', args=(post.created_at.year, post.created_at.month, post.created_at.day, post.slug)))