コード例 #1
0
def pokebolas():
    if request.method == "GET":
        return Response(SerializadorPokebola(Pokebola.select(),
                                             many=True).data,
                        status=STATUS_OK,
                        mimetype="application/json")
    elif request.method == "POST":
        attrs = json.loads(request.data.decode("utf8"))
        serializador = SerializadorPokebola(attrs=attrs)
        serializador.save()
        return Response(serializador.data,
                        status=STATUS_CREATED,
                        mimetype="application/json")
コード例 #2
0
def pokebola(pokebola_id):
    if request.method == "GET":
        try:
            return SerializadorPokebola(
                Pokebola.get(Pokebola.id == pokebola_id)).data
        except:
            return Response(status=STATUS_NOT_FOUND)
    elif request.method == "PUT":
        attrs = json.loads(request.data.decode("utf8"))
        pokebola = Pokebola.get(Pokebola.id == pokebola_id)
        serializador = SerializadorPokebola(pokebola, attrs=attrs)
        serializador.save()
        return Response(serializador.data,
                        status=STATUS_CREATED,
                        mimetype="application/json")
コード例 #3
0
def pokebolas_en_mochila(mochila_id):
    return SerializadorPokebola(
        Pokebola.filter(Pokebola.mochila == mochila_id), many=True).data