I have a view that displays object information when the correct URL is provided however I would like to create a similar view that returns url information from the record that is located next.
So in essence take the info from my first view, list/order it in some way preferably by date and return the records located next and previous in the list.
Can somebody please explain to me and provide a simple example of how I would do this. I am new to django and I am stuck. All Help is greatly appreciated. Thanks.
Here are the models URLs and views I have used
Model
class Body(models.Model):
type = models.ForeignKey(Content)
url = models.SlugField(unique=True, help_text='')
published = models.DateTimeField(default=datetime.now)
maintxt = models.CharField(max_length=200)
View
def news_view(request, url):
news = get_object_or_404(Body, url=url)
next = news.get_next_by_published().get_absolute_url()
return render_to_response('news/news_view.html', {
'news': news,
'next': next
}, context_instance=RequestContext(request))
URL
url(r'^/(?P<url>[\w\-]+)/$', 'news_view', name="news_view"),
Template
<a href="{{ next.get_absolute_url }}">Next</a></p>