def mochila(mochila_id): if request.method == "GET": try: return SerializadorMochila( Mochila.get(Mochila.id == mochila_id)).data except: return Response(status=STATUS_NOT_FOUND) elif request.method == "PUT": attrs = json.loads(request.data.decode("utf8")) mochila = Mochila.get(Mochila.id == mochila_id) serializador = SerializadorMochila(mochila, attrs=attrs) serializador.save() return Response(serializador.data, status=STATUS_CREATED, mimetype="application/json")
def mochila(mochila_id): if request.method == "GET": try: return SerializadorMochila(Mochila.get(Mochila.id == mochila_id)).data except: return Response(status=STATUS_NOT_FOUND) elif request.method == "PUT": attrs = json.loads(request.data.decode("utf8")) mochila = Mochila.get(Mochila.id == mochila_id) serializador = SerializadorMochila(mochila, attrs=attrs) serializador.save() return Response( serializador.data, status=STATUS_CREATED, mimetype="application/json" )
def mochilas(): if request.method == "GET": return Response(SerializadorMochila(Mochila.select(), many=True).data, status=STATUS_OK, mimetype="application/json") elif request.method == "POST": attrs = json.loads(request.data.decode("utf8")) serializador = SerializadorMochila(attrs=attrs) serializador.save() return Response(serializador.data, status=STATUS_CREATED, mimetype="application/json")
def mochilas(): if request.method == "GET": return Response( SerializadorMochila(Mochila.select(), many=True).data, status=STATUS_OK, mimetype="application/json" ) elif request.method == "POST": attrs = json.loads(request.data.decode("utf8")) serializador = SerializadorMochila(attrs=attrs) serializador.save() return Response( serializador.data, status=STATUS_CREATED, mimetype="application/json" )