26 lines
924 B
Python
26 lines
924 B
Python
|
|
from rest_framework import viewsets, permissions
|
||
|
|
from .models import FeaturedService
|
||
|
|
from .serializers import FeaturedServiceSerializer
|
||
|
|
|
||
|
|
|
||
|
|
class FeaturedServiceViewSet(viewsets.ModelViewSet):
|
||
|
|
queryset = FeaturedService.objects.filter(publish_status='published')
|
||
|
|
serializer_class = FeaturedServiceSerializer
|
||
|
|
permission_classes = [permissions.AllowAny]
|
||
|
|
|
||
|
|
def get_queryset(self):
|
||
|
|
queryset = FeaturedService.objects.all()
|
||
|
|
region_id = self.request.query_params.get('region')
|
||
|
|
category = self.request.query_params.get('category')
|
||
|
|
|
||
|
|
if region_id:
|
||
|
|
queryset = queryset.filter(region_id=region_id)
|
||
|
|
if category:
|
||
|
|
queryset = queryset.filter(category=category)
|
||
|
|
|
||
|
|
return queryset
|
||
|
|
|
||
|
|
def perform_create(self, serializer):
|
||
|
|
service = serializer.save(submitter=self.request.user)
|
||
|
|
service.submit_for_moderator_review()
|