forked from erp-dev/erp
feat: added cache to mdy_plate_staging api
This commit is contained in:
@@ -11,6 +11,9 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from django.core.cache import cache
|
||||||
|
from django.utils.decorators import method_decorator
|
||||||
|
from django.views.decorators.cache import cache_page
|
||||||
from django.db.models import F
|
from django.db.models import F
|
||||||
from rest_framework import serializers, viewsets
|
from rest_framework import serializers, viewsets
|
||||||
from rest_framework.pagination import LimitOffsetPagination
|
from rest_framework.pagination import LimitOffsetPagination
|
||||||
@@ -83,6 +86,7 @@ class MDYPlateOrderStagingSerializer(serializers.ModelSerializer):
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(cache_page(10), name='list')
|
||||||
class MDYPlateOrderStagingViewSet(viewsets.ReadOnlyModelViewSet):
|
class MDYPlateOrderStagingViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
"""开版暂存数据查询(只读)。"""
|
"""开版暂存数据查询(只读)。"""
|
||||||
|
|
||||||
@@ -100,3 +104,10 @@ class MDYPlateOrderStagingViewSet(viewsets.ReadOnlyModelViewSet):
|
|||||||
|
|
||||||
# 默认 -ctime;ctime 为空的放最后,避免老数据(未回填)跑到前面
|
# 默认 -ctime;ctime 为空的放最后,避免老数据(未回填)跑到前面
|
||||||
return qs.order_by(F("ctime").desc(nulls_last=True), F("id").desc())
|
return qs.order_by(F("ctime").desc(nulls_last=True), F("id").desc())
|
||||||
|
|
||||||
|
def filter_queryset(self, queryset):
|
||||||
|
qs = super().filter_queryset(queryset)
|
||||||
|
design_no = self.request.query_params.get(f"raw__{_PLATE_ORDER_DESIGN_NO_CONTROL_ID}")
|
||||||
|
if design_no:
|
||||||
|
qs = qs.filter(**{f"raw__{_PLATE_ORDER_DESIGN_NO_CONTROL_ID}": design_no})
|
||||||
|
return qs
|
||||||
|
|||||||
Reference in New Issue
Block a user