Skip to content

Commit

Permalink
Improving doctors viewsets with actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ajha63 committed Oct 3, 2024
1 parent 6848086 commit dfa85ba
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions doctors/viewsets.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
from rest_framework import viewsets

from rest_framework.decorators import action
from rest_framework.response import Response
from .serializers import DoctorSerializer
from .models import Doctor


class DoctorViewSet(viewsets.ModelViewSet):
serializer_class = DoctorSerializer
queryset = Doctor.objects.all()
queryset = Doctor.objects.all()

@action(['POST'], detail=True, url_path='vacation-set-on')
def set_on_vacation(self, requests, pk):
doctor = self.get_object()
doctor.is_on_vacation = True
doctor.save()
return Response({"status": "The doctor is on vacation"})

@action(['POST'], detail=True, url_path='vacation-set-off')
def set_off_vacation(self, requests, pk):
doctor = self.get_object()
doctor.is_on_vacation = False
doctor.save()
return Response({"status": "The doctor is not on vacations"})

0 comments on commit dfa85ba

Please sign in to comment.