Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.shortcuts import render, redirect
- from django.views import View
- from .models import Movie
- class MovieListView(View):
- def get(self, request):
- movies = Movie.objects.all()
- return render(request, 'movies/movie_list.html', {'movies': movies})
- class MovieCreateView(View):
- def get(self, request):
- return render(request, 'movies/movie_create.html')
- def post(self, request):
- title = request.POST.get('title')
- director = request.POST.get('director')
- release_date = request.POST.get('release_date')
- movie = Movie(title=title, director=director, release_date=release_date)
- movie.save()
- return redirect('movie_list')
- class MovieDeleteView(View):
- def post(self, request, movie_id):
- movie = Movie.objects.get(id=movie_id)
- movie.delete()
- return redirect('movie_list')
- class MovieUpdateView(View):
- def get(self, request, movie_id):
- movie = Movie.objects.get(id=movie_id)
- return render(request, 'movies/movie_update.html', {'movie': movie})
- def post(self, request, movie_id):
- movie = Movie.objects.get(id=movie_id)
- movie.title = request.POST['title']
- movie.director = request.POST['director']
- movie.release_date = request.POST['release_date']
- movie.save()
- return redirect('movie_list')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement