changing code structure

This commit is contained in:
xoliqberdiyev
2026-04-27 16:49:07 +05:00
parent 7134b2c185
commit e3e7f18d7f
21 changed files with 345 additions and 428 deletions

View File

@@ -1,24 +1,25 @@
# django
from django_core.mixins import BaseViewSetMixin
# django filters
from django_filters.rest_framework import DjangoFilterBackend
# swagger
from drf_spectacular.utils import OpenApiParameter, extend_schema
# rest framework
from rest_framework.filters import OrderingFilter
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.viewsets import ReadOnlyModelViewSet
# core apps
from core.apps.evaluation.filters.history import (
AutoevaluationhistoryFilter,
QuickevaluationhistoryFilter,
)
from core.apps.evaluation.models import AutoevaluationhistoryModel, QuickevaluationhistoryModel
from core.apps.evaluation.serializers.history import (
CreateAutoevaluationhistorySerializer,
CreateQuickevaluationhistorySerializer,
ListAutoevaluationhistorySerializer,
ListQuickevaluationhistorySerializer,
RetrieveAutoevaluationhistorySerializer,
RetrieveQuickevaluationhistorySerializer,
)
from core.apps.evaluation.serializers import history as serializers
@extend_schema(
@@ -31,13 +32,12 @@ from core.apps.evaluation.serializers.history import (
],
)
class AutoEvaluationHistoryView(BaseViewSetMixin, ReadOnlyModelViewSet):
# select_related("auto_evaluation") faqat retrieve uchun — list uchun kerak emas
queryset = AutoevaluationhistoryModel.objects.only(
"id", "auto_evaluation_id", "event_type",
"actor_id", "actor_full_name", "actor_role",
"meta", "created_at",
)
serializer_class = ListAutoevaluationhistorySerializer
serializer_class = serializers.ListAutoevaluationhistorySerializer
permission_classes = [AllowAny]
pagination_class = None
@@ -55,14 +55,13 @@ class AutoEvaluationHistoryView(BaseViewSetMixin, ReadOnlyModelViewSet):
action_permission_classes = {}
action_serializer_class = {
"list": ListAutoevaluationhistorySerializer,
"retrieve": RetrieveAutoevaluationhistorySerializer,
"create": CreateAutoevaluationhistorySerializer,
"list": serializers.ListAutoevaluationhistorySerializer,
"retrieve": serializers.RetrieveAutoevaluationhistorySerializer,
"create": serializers.CreateAutoevaluationhistorySerializer,
}
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
# Queryset bir marta evaluate qilinadi — COUNT uchun alohida query yo'q
results = list(queryset)
serializer = self.get_serializer(results, many=True)
return Response({
@@ -88,7 +87,7 @@ class QuickEvaluationHistoryView(BaseViewSetMixin, ReadOnlyModelViewSet):
"actor_id", "actor_full_name", "actor_role",
"meta", "created_at",
)
serializer_class = ListQuickevaluationhistorySerializer
serializer_class = serializers.ListQuickevaluationhistorySerializer
permission_classes = [AllowAny]
pagination_class = None
@@ -99,9 +98,9 @@ class QuickEvaluationHistoryView(BaseViewSetMixin, ReadOnlyModelViewSet):
action_permission_classes = {}
action_serializer_class = {
"list": ListQuickevaluationhistorySerializer,
"retrieve": RetrieveQuickevaluationhistorySerializer,
"create": CreateQuickevaluationhistorySerializer,
"list": serializers.ListQuickevaluationhistorySerializer,
"retrieve": serializers.RetrieveQuickevaluationhistorySerializer,
"create": serializers.CreateQuickevaluationhistorySerializer,
}
def list(self, request, *args, **kwargs):