diff --git a/app/api/serializers.py b/app/api/serializers.py index 692267a..efe9779 100644 --- a/app/api/serializers.py +++ b/app/api/serializers.py @@ -5,5 +5,5 @@ from rest_framework import serializers class NewsSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = News - fields = ['title', 'url', 'votes', 'created'] + fields = ['id', 'title', 'url', 'votes', 'created'] diff --git a/app/api/views.py b/app/api/views.py index 396fb91..3518582 100644 --- a/app/api/views.py +++ b/app/api/views.py @@ -2,6 +2,7 @@ from app.api.models import News from rest_framework import viewsets, mixins from app.api.serializers import NewsSerializer from rest_framework.response import Response +import json class NewsViewSet( mixins.UpdateModelMixin, @@ -19,11 +20,11 @@ class NewsViewSet( mixins.UpdateModelMixin, return Response(serializer.data) - def put(self, request, pk=None): + def put(self, request): # Update - my_news = News.objects.get(pk) + my_news = News.objects.get(pk=request.data['id']) my_news.votes = my_news.votes + 1 my_news.save() # Devolvemos la noticia modificada - serializer = News(my_news) + serializer = NewsSerializer(my_news) return Response(serializer.data) \ No newline at end of file diff --git a/app/web/forms.py b/app/web/forms.py new file mode 100644 index 0000000..2d443c3 --- /dev/null +++ b/app/web/forms.py @@ -0,0 +1,11 @@ +from django import forms + +class NewsForm(forms.Form): + title = forms.CharField( + label='Titulo', + required=True + ) + url = forms.URLField( + label='Ruta', + required=True + ) \ No newline at end of file diff --git a/app/web/templates/pages/add-news.html b/app/web/templates/pages/add-news.html index 566549b..0ddfb99 100644 --- a/app/web/templates/pages/add-news.html +++ b/app/web/templates/pages/add-news.html @@ -1,10 +1,11 @@ - - -
- -