Fundamentos de Django Rest Framework
Crea y escala APIs con Django REST Framework
Introducci贸n a las APIs, REST y JSON
Instalaci贸n de Django y Django REST Framework
Integraci贸n de Django REST Framework en proyectos Django
C贸mo crear modelos y serializadores en Django REST Framework
Implementar vistas basadas en funciones en Django REST Framework
Gesti贸n de Vistas Basadas en Funciones en Django REST Framework
驴C贸mo modificar y eliminar recursos con Django REST Framework?
Postman y cURL en Django REST Framework
Refactorizar las funciones a clases en Django REST Framework
Refactorizando vistas en Django REST Framework con vistas gen茅ricas
Documentaci贸n de APIs con Django REST, Swagger y OpenAPI
Vistas y Endpoints
Vistas Personalizadas y ViewSets en Django REST Framework
Manejos de Acciones con ViewSet en Django REST Framework
Autenticaci贸n y Gesti贸n de Roles en Django REST Framework
Manejo de Errores y Validaciones
Serializadores Avanzados
驴C贸mo implementar serializadores anidados en Django Django REST Framework?
驴C贸mo usar SerializerMethodField en Django REST Framework?
Endpoint Anidado para Appointments Usando @action
Testing y Desempe帽o
Pruebas Unitarias para Endpoints Anidados Usando APIClient
Throttling en Django REST Framework
You don't have access to this class
Keep learning! Join and start boosting your career
When creating APIs in Django REST Framework, we not only work with URLs for resources, but also with actions that allow us to execute specific operations, such as paying a card or, in this case, managing a doctor's vacation.
Doctor
model, we add the is_on_vacation
field, which will be a boolean field with default value False
.manage.py makemigrations
and then run migrate
to apply the changes to the database.@action
decorator. We import the decorator from rest_framework.decorators
.toggle_vacation
with the decorator and specify that only the POST
method will be allowed.detail=True
for the action to be applied to a specific resource, such as a doctor identified by its ID in the URL.get_object()
method of the ViewSet to get the current Doctor
object.True
and False
for the is_on_vacation
field. If it is set to True
, it changes it to False
and vice versa.Doctor
object is saved and a response is returned using Response
to report the updated status.True
and False
, we create two separate actions: one to enable vacation(set_on_vacation
) and one to disable it(set_off_vacation
).POST
request has a predictable behavior, which improves the endpoint's idempotency.url_path
parameter inside the @action
decorator to define URLs with hyphens, e.g. set-on-vacation
.POST
requests to the generated URLs.is_on_vacation
field changes correctly in the database.Patient
ViewSet.Contributions 4
Questions 0
Want to see more contributions, questions and answers from the community?