diff --git a/backend/categories/serializers.py b/backend/categories/serializers.py new file mode 100644 index 0000000..b0548e1 --- /dev/null +++ b/backend/categories/serializers.py @@ -0,0 +1,8 @@ +from rest_framework import serializers +from .models import Category + +class CategorySerializer(serializers.ModelSerializer): + + class Meta: + model = Category + fields = "__all__" \ No newline at end of file diff --git a/backend/categories/urls.py b/backend/categories/urls.py index 4bfdf2d..6af068e 100644 --- a/backend/categories/urls.py +++ b/backend/categories/urls.py @@ -2,5 +2,23 @@ from . import views urlpatterns = [ - path("", views.categories), + path( + "", + views.CategoryViewSet.as_view( + { + "get": "list", + "post": "create", + } + ), + ), + path( + "", + views.CategoryViewSet.as_view( + { + "get": "retrieve", + "put": "partial_update", + "delete": "destroy", + } + ), + ), ] \ No newline at end of file diff --git a/backend/categories/views.py b/backend/categories/views.py index c1c7e75..c480c65 100644 --- a/backend/categories/views.py +++ b/backend/categories/views.py @@ -1,12 +1,8 @@ -from rest_framework.decorators import api_view -from rest_framework.response import Response +from rest_framework.viewsets import ModelViewSet from .models import Category +from .serializers import CategorySerializer -@api_view() -def categories(request): - return Response( - { - "ok": True, - "categories": Category.objects.all() - } - ) \ No newline at end of file +class CategoryViewSet(ModelViewSet): + + serializer_class = CategorySerializer + queryset = Category.objects.all() \ No newline at end of file