def prediccion(request): if request.method == 'POST': data = JSONParser().parse(request) series = Serie.objects.all() serializer = SerieSerializer(series, many=True) markov = markovgen.Markov() for x in serializer.data: markov.addText(x["texto"]) if(data["texto"] in markov.cachee): return JSONResponse(markov.cachee[data["texto"]]) else: return HttpResponse(status=404)
def serie_detail(request, pk): # try: # serie = Serie.objects.get(pk=pk) # except Serie.DoesNotExist: # return HttpResponse(status=404) if request.method == 'GET': series = Serie.objects.all() serializer = SerieSerializer(series, many=True) markov = markovgen.Markov() for x in serializer.data: markov.addText(x["texto"]) return JSONResponse(markov.cachee[pk])
def serie_list(request): if request.method == 'GET': series = Serie.objects.all() serializer = SerieSerializer(series, many=True) return JSONResponse(serializer.data) elif request.method == 'POST': data = JSONParser().parse(request) serializer = SerieSerializer(data=data) if serializer.is_valid(): serializer.save() return JSONResponse(serializer.data, status=201) return JSONResponse(serializer.errors, status=400)
def prediccion_lista(request): if request.method == 'POST': data = JSONParser().parse(request) serializer = SerieSerializer(data=data) if serializer.is_valid(): serializer.save() series = Serie.objects.all() serializer = SerieSerializer(series, many=True) markov = markovgen.Markov() for x in serializer.data: markov.addText(x["texto"]) return JSONResponse(markov.cachee) if request.method == 'GET': series = Serie.objects.all() serializer = SerieSerializer(series, many=True) markov = markovgen.Markov() for x in serializer.data: markov.addText(x["texto"]) return JSONResponse(markov.cachee)
def serie_list(request): if request.method == 'GET': series = Serie.objects.all() serializer = SerieSerializer(series, many=True) markov = markovgen.Markov() for x in serializer.data: markov.addText(x["texto"]) return JSONResponse(markov.cachee) elif request.method == 'POST': data = JSONParser().parse(request) serializer = SerieSerializer(data=data) if serializer.is_valid(): serializer.save() return JSONResponse({"rest":"ok"}, status=201) return JSONResponse(serializer.errors, status=400)
def serie_detail(request, pk): try: serie = Serie.objects.get(pk=pk) except Serie.DoesNotExist: return HttpResponse(status=404) if request.method == 'GET': serializer = SerieSerializer(serie) return JSONResponse(serializer.data) elif request.method == 'PUT': data = JSONParser().parse(request) serializer = SerieSerializer(serie, data=data) if serializer.is_valid(): serializer.save() return JSONResponse(serializer.data) return JSONResponse(serializer.errors, status=400) elif request.method == 'DELETE': serie.delete() return HttpResponse(status=204)
def series(self, request, pk=None): espacio = self.get_object() if request.method == "GET": serializer = SerieSerializer(espacio.series, many=True) return Response(status=status.HTTP_200_OK, data=serializer.data) if request.method == "POST": espacio_id = request.data["serie"] for serie_id in espacio_id: serie = Espacio.objects.all(id=int(serie_id)) espacio.serie.add(serie) return Response(status=status.HTTP_201_CREATED) if request.methos == "DELETE": espacio_id = request.data["serie"] for serie_id in espacio_id: serie = Espacio.objects.all(id=int(serie_id)) espacio.serie.remove(serie) return Response(status=status.HTTP_204_NO_CONTENT)
from series.serializers import SerieSerializer serializer = SerieSerializer() print(repr(serializer)) > SerieSerializer(): id = IntegerField(label='ID', read_only=True) name = CharField(max_length=100) release_date = DateField() rating = IntegerField(required=False) category = ChoiceField(choices=(('horror', 'Horror'), ('comedy', 'Comedy'), ('action', 'Action'), ('drama', 'Drama')))
def texto_lista(request): if request.method == 'POST': series = Serie.objects.all() serializer = SerieSerializer(series, many=True) return JSONResponse(serializer.data)
def serie_listando(request): if request.method == 'GET': series = Serie.objects.all() serializer = SerieSerializer(series, many=True) return JSONResponse(serializer.data)
def series(self, request, pk=None): categoria = self.get_object() if request == "GET": serializer = SerieSerializer(categoria.serie, many=True) return Response(status=status.HTTP_200_OK, data=serializer.data)
def cseries(self, request, pk=None): series = Serie.objects.filter(comments__author__id=pk) return Response(SerieSerializer(serie).data for serie in series)