Advertisement
Guest User

Untitled

a guest
Jun 4th, 2021
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. from django.shortcuts import render
  2.  
  3. from .models import Film, Series
  4.  
  5. from .utils import ObjectDetailMixin
  6. from django.views.generic import View
  7.  
  8. from django.views.generic import DetailView
  9.  
  10. from django.http import HttpResponse
  11.  
  12.  
  13. # Create your views here:
  14. def index(request):
  15. films = Film.objects.all()
  16. series = Series.objects.all()
  17. return render(request, 'KinomonsterApp/base.html', context={'films': films, 'series': series})
  18.  
  19.  
  20. # class FilmDetail(ObjectDetailMixin, View):
  21. # def get(self, request, *args, **kwargs):
  22. # model = kwargs.get('pk')
  23. # template = 'KinomonsterApp/film_detail.html'
  24. # return render(request, 'KinomonsterApp/film_detail.html', context={'model': model})
  25.  
  26. class FilmDetailView(DetailView):
  27.  
  28. model = Film
  29. template_name = 'KinomonsterApp/film_detail.html'
  30.  
  31. def get_context_data(self, **kwargs):
  32. # Call the base implementation first to get a context
  33. context = super().get_context_data(**kwargs)
  34. # Add in a QuerySet of all the books
  35. print(kwargs.get('pk'))
  36. # context['film'] = Film.objects.get(id=kwargs.get('pk'))
  37. return context
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement