Skip to content

Commit

Permalink
fix: filtering and improve serilizer
Browse files Browse the repository at this point in the history
  • Loading branch information
martcl committed Oct 9, 2023
1 parent 99c9cd0 commit c724155
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/communication/serializers/banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ class Meta:
"updated_at",
"image",
"image_alt",
"is_visible",
"is_expired",
)
7 changes: 5 additions & 2 deletions app/communication/views/banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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")

0 comments on commit c724155

Please sign in to comment.