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