Django Rest Framework API #23 / Override UPDATE | PUT Action | Method for ModelViewSet and ApiView.

Опубликовано: 06 Октябрь 2024
на канале: Code Environment
16,326
172

What you will learn:
How to override UPDATE action | method inside Django REST Framework. -
How to override UPDATE action | method inside ModelViewSet.
How to override PUT action | method inside ApiView.

How to read the data that was sent through a PUT request using (request) argument then update an object and save it in the database.

Note: If you have more than on object then you need to use " url variables " with API Views like:
"localhost:8000/cars_app/cars?id=1"
and inside your put method you need to add:
id = request.query_params["id"]
# To get the object id from the url
car_object = Cars.objects.get(id=id)
# To get the object that we need to update

Source code: https://github.com/CodeEnvironment/dj...

🎧 Music :    • Study music | Programming music | Lof...  
Music Channel : @tuningthecode

APIView GET & POST Request and Response:
   • Django Rest Framework API #17  APIVie...  

Override Create Action | CREATE Method:
   • Django Rest Framework API #14 / Overr...  

Override Delete Action (destroy method) DELETE Request:
   • Django Rest Framework API #15 / Overr...  

ModelViewset With Serializer and Router:
   • Django Rest Framework API #11 / Model...