Esempio n. 1
0
def detalle_promocion(request, pk):
    """
    Retrieve, update or delete a code snippet.
    """
    try:
        promocion = Promocion.objects.get(pk=pk)
    except Promocion.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = PromocionSerializer(promocion)
        return JSONResponse(serializer.data)

    elif request.method == 'PUT':
        data = JSONParser().parse(request)
        serializer = PromocionSerializer(promocion, data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data)
        else:
            return JSONResponse(serializer.errors, status=400)

    elif request.method == 'DELETE':
        promocion.delete()
        return HttpResponse(status=204)
Esempio n. 2
0
def lista_promociones(request):
    """
    List all code restaurante, or create a new snippet.
    """
    if request.method == 'GET':
        promocion = Promocion.objects.all()
        serializer = PromocionSerializer(promocion, many=True)
        return JSONResponse(serializer.data)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = PromocionSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        else:
            return JSONResponse(serializer.errors, status=400)