I'm using a class based view DetailView to handle the layout of a blog post.
In the template, I need to implement a button to show previous/next posts ordered by timestamp. For this reason, I need to override the context by customising the get_context_data(self)
method.
In the context I thus need to add the instances of prev/next entries by insertion_date
relative to current post.
views.py
class EntryDetailView(DetailView):
model = Entry
def get_context_data(self, **kwargs):
context = super(EntryDetailView, self).get_context_data(**kwargs)
context['base_url'] = self.request.build_absolute_uri("/").rstrip("/")
return context
models.py
from .managers import EntryManager
class Entry(models.Model):
""" Blog Entry
"""
insertion_date = models.DateTimeField('inserimento', auto_now_add=True)
Thank you for any help you could provide.
get_next_by_FOO
- Daniel Rosemanself.object
, see the docs. - Daniel Roseman