From 299c5cb3779d673107dbb7e7993214b6a21a290f Mon Sep 17 00:00:00 2001 From: jiyoon607 Date: Mon, 26 May 2025 20:18:48 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=EA=B4=80=EB=A6=AC=EC=9E=90=EB=B7=B0=20?= =?UTF-8?q?=EB=8C=80=EA=B8=B0=20=EC=A0=95=EB=A0=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manager/views.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/manager/views.py b/manager/views.py index 7fdc44e..8c4632e 100644 --- a/manager/views.py +++ b/manager/views.py @@ -44,7 +44,32 @@ def get_booth_queryset(self, request, statuses): try: booth = request.user.manager_user.booth - queryset = Waiting.objects.filter(booth=booth, waiting_status__in=statuses).order_by('created_at') + # waiting_status가 기타인 경우: 오래된 순 정렬 + other_qs = Waiting.objects.filter( + booth=booth + ).exclude( + waiting_status__in=['entered', 'canceled', 'time_over'] + ).annotate( + status_priority=Value(0, output_field=IntegerField()) + ).order_by('created_at') + + # waiting_status가 canceled, time_over, entered: 최신 순 정렬 + status_qs = Waiting.objects.filter( + booth=booth, + waiting_status__in=['canceled', 'time_over', 'entered'] + ).annotate( + status_priority=Case( + When(waiting_status__in=['canceled', 'time_over'], then=Value(1)), + When(waiting_status='entered', then=Value(2)), + output_field=IntegerField() + ) + ).order_by('status_priority', '-created_at') + + # 병합 + status_qs = status_qs.filter(waiting_status__in=statuses) + other_qs = other_qs.filter(waiting_status__in=statuses) + queryset = list(chain(other_qs, status_qs)) + serializer = ManagerWaitingListSerializer(queryset, many=True) return custom_response( serializer.data,