Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from .models import Post
- from django.views.generic import ListView
- class LastViewetObject :
- # override get_context_data for adding the last_viewed_post on the context
- def get_context_data(self,**kwargs):
- context = super().get_context_data(**kwargs)
- post_id = self.request.session.get('last_viewed_product_id',False)
- context['last_viewed_post'] = self.model.objects.get(id=post_id)
- return context
- class PostListView(ListView,LastViewetObject):
- queryset = Post.objects.all()
- template_name = 'post_view.html'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement