Skip to content

Commit

Permalink
get next/previous by now working
Browse files Browse the repository at this point in the history
  • Loading branch information
hypertexthero committed Sep 6, 2013
1 parent b180cf2 commit 98fba8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
13 changes: 0 additions & 13 deletions models.py
Expand Up @@ -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."""
Expand Down
26 changes: 13 additions & 13 deletions templates/hth/entry_detail.html
Expand Up @@ -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 #}
<dl>
<dt><a href="{{ object.url }}">{{ object.title }}</a> &nbsp;<a class="plink" title="Permanent link to {{ object.title }}" href="{{ object.get_linked_list_url }}"># {{ object.pub_date|date:"d b Y" }}</a></dt>
<dd>
{{ object.body_html|safe }}
</dd>
<dt><a href="{{ object.url }}">{{ object.title }}</a> &nbsp;<a class="plink" title="Permanent link to {{ object.title }}" href="{{ object.get_linked_list_url }}"># {{ object.pub_date|date:"d b Y" }}</a></dt>
<dd>
{{ object.body_html|safe }}
</dd>
</dl>

{% else %} {# otherwise it is an original article #}
Expand All @@ -39,17 +39,17 @@ <h1><a href="{{ object.get_absolute_url }}" rel="permalink" title="Permanent lin
<p class="quiet"><time pubdate="pubdate">{{ object.pub_date|date:"l, F j Y" }}</time></p>
{{ object.body_html|safe }}

{% endif %} {# end if object.kind == "L" #}

<p class="paging">
{% if object.get_prev_article %}
<a rel="prev" href="{{ object.get_prev_article.get_absolute_url }}"><i>Previous:</i> <b>{{ object.get_prev_article }}</b></a>
{% endif %}
<br>
{% if object.get_next_article %}
<a rel="next" href="{{ object.get_next_article.get_absolute_url }}"><i>Next:</i> <b>{{ object.get_next_article }}</b></a>
{% 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 %}
<a rel="prev" href="{{ object.get_previous_by_pub_date.get_absolute_url }}"><i>Previous:</i> <b>{{ object.get_previous_by_pub_date }}</b></a>
{% endif %}
<br>
{% if object.get_next_by_pub_date %}
<a rel="next" href="{{ object.get_next_by_pub_date.get_absolute_url }}"><i>Next:</i> <b>{{ object.get_next_by_pub_date }}</b></a>
{% endif %}
</p>

{% endif %} {# end if object.kind == "L" #}

{% endblock %}

0 comments on commit 98fba8d

Please sign in to comment.