diff --git a/selfblog/blog/models.py b/selfblog/blog/models.py index b2e4e1d..4c62be8 100644 --- a/selfblog/blog/models.py +++ b/selfblog/blog/models.py @@ -1,8 +1,9 @@ -#coding:utf-8 +# coding:utf-8 from datetime import datetime from django.db import models from django.contrib.auth.models import User +from django.utils.functional import cached_property from selfblog import settings from utils.cache import cache_decorator @@ -77,6 +78,16 @@ def tags_list(self): def get_absolute_url(self): return '%s/%s.html' % (settings.DOMAIN, self.alias) + @cached_property + def next_post(self): + # 下一篇 + return Post.objects.filter(id__gt=self.id, status=0).order_by('id').first() + + @cached_property + def prev_post(self): + # 前一篇 + return Post.objects.filter(id__lt=self.id, status=0).first() + @classmethod @cache_decorator(1*60) def get_recently_posts(cls, num): diff --git a/selfblog/blog/templates/detail.html b/selfblog/blog/templates/detail.html index b9288d6..bad2b12 100644 --- a/selfblog/blog/templates/detail.html +++ b/selfblog/blog/templates/detail.html @@ -77,15 +77,15 @@