Add product review model, serializer, and API endpoint
Introduces a Review model for product reviews, including rating and comment fields. Adds a public serializer and a ModelViewSet for reviews with search and ordering capabilities. Also updates the frontend API client to use the correct token refresh endpoint and improves FormData handling.
This commit is contained in:
@@ -4,8 +4,8 @@ from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
import base64
|
||||
|
||||
from .models import Refund
|
||||
from .serializers import RefundCreatePublicSerializer
|
||||
from .models import Refund, Review
|
||||
from .serializers import RefundCreatePublicSerializer, ReviewSerializerPublic
|
||||
|
||||
|
||||
from django.db import transaction
|
||||
@@ -414,4 +414,16 @@ class RefundPublicView(APIView):
|
||||
"base64": pdf_b64,
|
||||
},
|
||||
}
|
||||
return Response(resp, status=status.HTTP_201_CREATED)
|
||||
return Response(resp, status=status.HTTP_201_CREATED)
|
||||
|
||||
|
||||
class ReviewPublicViewSet(viewsets.ModelViewSet):
|
||||
queryset = Review.objects.all()
|
||||
serializer_class = ReviewSerializerPublic
|
||||
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
|
||||
filter_backends = [filters.SearchFilter, filters.OrderingFilter]
|
||||
search_fields = ["product__name", "user__username", "comment"]
|
||||
ordering_fields = ["rating", "created_at"]
|
||||
ordering = ["-created_at"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user