-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improving doctors viewsets with actions
- Loading branch information
Showing
1 changed file
with
18 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}) | ||
|