Skip to content

Commit

Permalink
add category url & view
Browse files Browse the repository at this point in the history
  • Loading branch information
parkm2ngyu00 committed Aug 18, 2024
1 parent 72f3bdc commit e77b9ed
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
8 changes: 8 additions & 0 deletions backend/categories/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import serializers
from .models import Category

class CategorySerializer(serializers.ModelSerializer):

class Meta:
model = Category
fields = "__all__"
20 changes: 19 additions & 1 deletion backend/categories/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,23 @@
from . import views

urlpatterns = [
path("", views.categories),
path(
"",
views.CategoryViewSet.as_view(
{
"get": "list",
"post": "create",
}
),
),
path(
"<int:pk>",
views.CategoryViewSet.as_view(
{
"get": "retrieve",
"put": "partial_update",
"delete": "destroy",
}
),
),
]
16 changes: 6 additions & 10 deletions backend/categories/views.py
Original file line number Diff line number Diff line change
@@ -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()
}
)
class CategoryViewSet(ModelViewSet):

serializer_class = CategorySerializer
queryset = Category.objects.all()

0 comments on commit e77b9ed

Please sign in to comment.