api response struktra ozgardi qb query kamytraildi #34
29
core/apps/evaluation/migrations/0024_add_history_indexes.py
Normal file
29
core/apps/evaluation/migrations/0024_add_history_indexes.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# Generated by Django 5.2.7 on 2026-04-02 11:08
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('evaluation', '0023_autoevaluationhistorymodel_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddIndex(
|
||||
model_name='autoevaluationhistorymodel',
|
||||
index=models.Index(fields=['auto_evaluation_id', 'created_at'], name='auto_hist_eval_date_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='autoevaluationhistorymodel',
|
||||
index=models.Index(fields=['event_type'], name='auto_hist_event_type_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='quickevaluationhistorymodel',
|
||||
index=models.Index(fields=['quick_evaluation_id', 'created_at'], name='quick_hist_eval_date_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='quickevaluationhistorymodel',
|
||||
index=models.Index(fields=['event_type'], name='quick_hist_event_type_idx'),
|
||||
),
|
||||
]
|
||||
@@ -56,6 +56,12 @@ class AutoevaluationhistoryModel(models.Model):
|
||||
verbose_name = _("Auto Evaluation History")
|
||||
verbose_name_plural = _("Auto Evaluation Histories")
|
||||
ordering = ["created_at"]
|
||||
indexes = [
|
||||
# Asosiy query: bir baholash tarixi + sana bo'yicha tartib
|
||||
models.Index(fields=["auto_evaluation_id", "created_at"], name="auto_hist_eval_date_idx"),
|
||||
# event_type bo'yicha filter
|
||||
models.Index(fields=["event_type"], name="auto_hist_event_type_idx"),
|
||||
]
|
||||
|
||||
|
||||
class QuickevaluationhistoryModel(models.Model):
|
||||
@@ -110,3 +116,9 @@ class QuickevaluationhistoryModel(models.Model):
|
||||
verbose_name = _("Quick Evaluation History")
|
||||
verbose_name_plural = _("Quick Evaluation Histories")
|
||||
ordering = ["created_at"]
|
||||
indexes = [
|
||||
# Asosiy query: bir baholash tarixi + sana bo'yicha tartib
|
||||
models.Index(fields=["quick_evaluation_id", "created_at"], name="quick_hist_eval_date_idx"),
|
||||
# event_type bo'yicha filter
|
||||
models.Index(fields=["event_type"], name="quick_hist_event_type_idx"),
|
||||
]
|
||||
|
||||
@@ -3,6 +3,7 @@ from django_filters.rest_framework import DjangoFilterBackend
|
||||
from drf_spectacular.utils import OpenApiParameter, extend_schema
|
||||
from rest_framework.filters import OrderingFilter
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.viewsets import ReadOnlyModelViewSet
|
||||
|
||||
from core.apps.evaluation.filters.history import (
|
||||
@@ -30,10 +31,15 @@ from core.apps.evaluation.serializers.history import (
|
||||
],
|
||||
)
|
||||
class AutoEvaluationHistoryView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
||||
queryset = AutoevaluationhistoryModel.objects.select_related().all()
|
||||
# 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
|
||||
permission_classes = [AllowAny]
|
||||
pagination_class = None # History uchun pagination kerak emas
|
||||
pagination_class = None
|
||||
|
||||
filter_backends = [DjangoFilterBackend, OrderingFilter]
|
||||
filterset_class = AutoevaluationhistoryFilter
|
||||
@@ -47,6 +53,18 @@ class AutoEvaluationHistoryView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
||||
"create": 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({
|
||||
"count": len(results),
|
||||
"next": None,
|
||||
"previous": None,
|
||||
"results": serializer.data,
|
||||
})
|
||||
|
||||
|
||||
@extend_schema(
|
||||
tags=["QuickEvaluationHistory"],
|
||||
@@ -58,10 +76,14 @@ class AutoEvaluationHistoryView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
||||
],
|
||||
)
|
||||
class QuickEvaluationHistoryView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
||||
queryset = QuickevaluationhistoryModel.objects.select_related().all()
|
||||
queryset = QuickevaluationhistoryModel.objects.only(
|
||||
"id", "quick_evaluation_id", "event_type",
|
||||
"actor_id", "actor_full_name", "actor_role",
|
||||
"meta", "created_at",
|
||||
)
|
||||
serializer_class = ListQuickevaluationhistorySerializer
|
||||
permission_classes = [AllowAny]
|
||||
pagination_class = None # History uchun pagination kerak emas
|
||||
pagination_class = None
|
||||
|
||||
filter_backends = [DjangoFilterBackend, OrderingFilter]
|
||||
filterset_class = QuickevaluationhistoryFilter
|
||||
@@ -74,3 +96,14 @@ class QuickEvaluationHistoryView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
||||
"retrieve": RetrieveQuickevaluationhistorySerializer,
|
||||
"create": CreateQuickevaluationhistorySerializer,
|
||||
}
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
queryset = self.filter_queryset(self.get_queryset())
|
||||
results = list(queryset)
|
||||
serializer = self.get_serializer(results, many=True)
|
||||
return Response({
|
||||
"count": len(results),
|
||||
"next": None,
|
||||
"previous": None,
|
||||
"results": serializer.data,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user