Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. from .models import Post
  2. from django.views.generic import ListView
  3.  
  4. class LastViewetObject :
  5.  
  6. # override get_context_data for adding the last_viewed_post on the context
  7. def get_context_data(self,**kwargs):
  8. context = super().get_context_data(**kwargs)
  9. post_id = self.request.session.get('last_viewed_product_id',False)
  10. context['last_viewed_post'] = self.model.objects.get(id=post_id)
  11. return context
  12.  
  13. class PostListView(ListView,LastViewetObject):
  14. queryset = Post.objects.all()
  15. template_name = 'post_view.html'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement