From 98fba8dcbc1e619fe93a721624419d998a8f18ca Mon Sep 17 00:00:00 2001 From: Simon Griffee Date: Fri, 6 Sep 2013 16:08:58 +0200 Subject: [PATCH] get next/previous by now working --- models.py | 13 ------------- templates/hth/entry_detail.html | 26 +++++++++++++------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/models.py b/models.py index 81aa042..5b10173 100644 --- a/models.py +++ b/models.py @@ -87,19 +87,6 @@ def get_linked_list_url(self): 'day': self.pub_date.strftime("%d"), 'slug': self.slug}) - -# http://stackoverflow.com/questions/2214852/next-previous-links-from-a-query-set-generic-views - def get_next_article(self): - next = Entry.objects.filter(id__gt=self.id, kind='A', is_active=True) - if next: - return next[0] - return False - - def get_prev_article(self): - prev = Entry.objects.filter(id__lt=self.id, kind='A', is_active=True) - if prev: - return prev[0] - return False def is_published(self): """Return True if the entry is publicly accessible.""" diff --git a/templates/hth/entry_detail.html b/templates/hth/entry_detail.html index f1e62a0..aefb8d7 100644 --- a/templates/hth/entry_detail.html +++ b/templates/hth/entry_detail.html @@ -27,10 +27,10 @@ {% if object.kind == "L" %} {# if a value for linkurl is present in the head of files this is a link to another site #}
-
{{ object.title }}  # {{ object.pub_date|date:"d b Y" }}
-
- {{ object.body_html|safe }} -
+
{{ object.title }}  # {{ object.pub_date|date:"d b Y" }}
+
+ {{ object.body_html|safe }} +
{% else %} {# otherwise it is an original article #} @@ -39,17 +39,17 @@

{{ object.body_html|safe }} +{% endif %} {# end if object.kind == "L" #}

- {% if object.get_prev_article %} - - {% endif %} -
- {% if object.get_next_article %} - - {% endif %} + {# https://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#django.db.models.Model.get_next_by_FOO #} + {% if object.get_previous_by_pub_date %} + + {% endif %} +
+ {% if object.get_next_by_pub_date %} + + {% endif %}

-{% endif %} {# end if object.kind == "L" #} - {% endblock %} \ No newline at end of file