You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

44 lines
1.8 KiB

from django.db.models import Q
from rest_framework.authentication import TokenAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.viewsets import ModelViewSet
from apps.account.permissions import IsSuperAdmin
from apps.dobodbi_calendar.models import CalendarOccasions
from apps.dobodbi_calendar.serializers_admin import CalendarOccasionAdminSerializer
class AdminCalendarOccasionViewSet(ModelViewSet):
serializer_class = CalendarOccasionAdminSerializer
permission_classes = [IsAuthenticated, IsSuperAdmin]
authentication_classes = [TokenAuthentication]
pagination_class = None
def get_queryset(self):
queryset = CalendarOccasions.objects.all()
search_query = self.request.query_params.get("search")
if search_query:
queryset = queryset.filter(
Q(title__icontains=search_query)
| Q(event_type__icontains=search_query)
| Q(occasion_type__icontains=search_query)
)
event_type = self.request.query_params.get("event_type")
if event_type and event_type != "all":
queryset = queryset.filter(event_type=event_type)
occasion_type = self.request.query_params.get("occasion_type")
if occasion_type and occasion_type != "all":
queryset = queryset.filter(occasion_type=occasion_type)
yearly = self.request.query_params.get("is_yearly")
if yearly in {"true", "false"}:
queryset = queryset.filter(is_yearly=yearly == "true")
global_filter = self.request.query_params.get("is_global")
if global_filter in {"true", "false"}:
queryset = queryset.filter(is_global=global_filter == "true")
return queryset.order_by("-updated_at", "-id")