from django.shortcuts import render
from moviesinfo.forms import MovieForm
from moviesinfo.models import Movie

# Create your views here.
def index_view(request):
    return render(request, 'moviesinfo/index.html')

def add_movie_view(request):
    form=MovieForm()
    if request.method=='POST':
        form=MovieForm(request.POST)
        if form.is_valid():
            form.save()
        return index_view(request)
    return render(request, 'moviesinfo/addmovie.html', {'form': form})

def list_movie_view(request):
    movies_list=Movie.objects.all().order_by('-rating')
    return render(request, 'moviesinfo/listmovies.html', {'movies_list': movies_list})
