Wednesday, October 27, 2010

Problems limiting get_next_by_FOO inside a django view?

have used get_next_by_FOO inside my view to display an absolute url
for the following item within a set of records however when it gets to
the end of the query set an error is raised.

how do I stop my view from raising this error and instead just
outputting some html letting me know that it has come to the end of
the set?

All help is greatly appreciated.

def news_view(request, url):
news = get_object_or_404(Body, url=url)
next = news.get_next_by_published()
pre = news.get_previous_by_published()
return render_to_response('news/news_view.html', {
'news': news,
'pre': pre,
'next': next
}, context_instance=RequestContext(request)


current template
<a href="{{ next.get_absolute_url }}">Next News</a></p>
<a href="{{ pre.get_absolute_url }}">Previous News</a></p>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate