Пример #1
0
def vista(request):
    p = Pelicula.objects.get(id=request.POST['id'])

    try:
        p.getVista(request.user.id)
        v = Vista.objects.get(usuario=User.objects.get(id=request.user.id),
                              pelicula=Pelicula.objects.get(id=request.POST['id']))
        v.delete()
    except:
        v = Vista(usuario=User.objects.get(id=request.user.id), pelicula=Pelicula.objects.get(id=request.POST['id']))
        v.save()

    return HttpResponse('success')
Пример #2
0
def votar(request):
    peliculaid = int(request.POST['id'])
    valor = float(request.POST['value'])

    p = Pelicula.objects.get(id=peliculaid)

    try:
        p.getVista(request.user.id)
        v = Vista.objects.get(usuario=User.objects.get(id=request.user.id),
                              pelicula=Pelicula.objects.get(id=peliculaid))
        v.voto = valor
        v.save()
    except:
        v = Vista(usuario=User.objects.get(id=request.user.id),
                  pelicula=Pelicula.objects.get(id=peliculaid), voto=valor)
        v.save()

    return HttpResponse('success')