From c7241553c529e85e00c841b8fa14b3450b900ad3 Mon Sep 17 00:00:00 2001 From: Martin Clementz Date: Mon, 9 Oct 2023 18:33:11 +0200 Subject: [PATCH] fix: filtering and improve serilizer --- app/communication/serializers/banner.py | 2 ++ app/communication/views/banner.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/communication/serializers/banner.py b/app/communication/serializers/banner.py index e78c2fa9c..66c8149b3 100644 --- a/app/communication/serializers/banner.py +++ b/app/communication/serializers/banner.py @@ -17,4 +17,6 @@ class Meta: "updated_at", "image", "image_alt", + "is_visible", + "is_expired", ) diff --git a/app/communication/views/banner.py b/app/communication/views/banner.py index 834f16794..e9234762a 100644 --- a/app/communication/views/banner.py +++ b/app/communication/views/banner.py @@ -23,12 +23,12 @@ class Meta: def filter_is_visible(self, queryset, name, value): if value: - return queryset.filter(is_visible=True) + return queryset.filter(visible_from__lte=now(), visible_until__gte=now()) return queryset def filter_is_expired(self, queryset, name, value): if value: - return queryset.filter(is_expired=True) + return queryset.filter(visible_until__lt=now()) return queryset @@ -52,3 +52,6 @@ def visible(self, request): ) serializer = BannerSerializer(banner, context={"request": request}, many=True) return Response(serializer.data, status=status.HTTP_200_OK) + + def get_queryset(self): + return self.queryset.order_by("-visible_from") \ No newline at end of file