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

  Рет қаралды 16,320

Code Environment

Code Environment

Күн бұрын

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: github.com/Cod...
🎧 Music : • Study music | Programm...
Music Channel : @tuningthecode
APIView GET & POST Request and Response:
• Django Rest Framework ...
Override Create Action | CREATE Method:
• Django Rest Framework ...
Override Delete Action (destroy method) DELETE Request:
• Django Rest Framework ...
ModelViewset With Serializer and Router:
• Django Rest Framework ...

Пікірлер: 14
@codeenvironment
@codeenvironment 3 жыл бұрын
Note: I forgot to mention that 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
@ВладиславВасилец-й7е
@ВладиславВасилец-й7е 2 жыл бұрын
намучался с этим put... Спасибо, чувак
@kglmgaming.official
@kglmgaming.official Жыл бұрын
well played sir well played
@think-dotest2166
@think-dotest2166 4 жыл бұрын
I was waiting for this video, thank you man✌🏻
@stevesteve619
@stevesteve619 4 жыл бұрын
Thank you for the video 👍🏻
@yusufuslu831
@yusufuslu831 Жыл бұрын
it's save my day
@Imaginaz
@Imaginaz Жыл бұрын
Appreciate for clear explanation and help me to solve my issues. support you +1 sub.
@codeenvironment
@codeenvironment Жыл бұрын
Thank you Alongkorn, I’m glad I could help 🙂.
@shadow2731
@shadow2731 9 ай бұрын
i need use controller and service used django framework api
@guidocaseres4466
@guidocaseres4466 3 жыл бұрын
Hi! I can't get my car with id = 1 by going to the URL "localhost:8000/cars_app/cars/1/". I have to write "localhost:8000/cars_app/cars?id=1" and maybe for that reason I can't update the object. Did you edit your code to be able to do that? Thanks!
@codeenvironment
@codeenvironment 3 жыл бұрын
Please tell me what is the response you are getting when using the: “localhost:8000/cars-app/cars/1/“
@guidocaseres4466
@guidocaseres4466 3 жыл бұрын
@@codeenvironment I have a response with all Car objects. Here is my code: def get(self, request, *args, **kwargs): try: id = request.query_params["id"] if(id != None): auto = Cars.objects.get(id = id) serializer = CarsSerializador(auto) except: autos = self.get_queryset() serializer = CarsSerializador(autos, many = True) return Response(serializer.data)
@codeenvironment
@codeenvironment 3 жыл бұрын
Good, so 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"] car_object = Cars.objects.get(id=id) after that you should be able to update.
@przemiymaciej4133
@przemiymaciej4133 Жыл бұрын
diesel will be 740d not 740i
GET, UPDATE, POST, DELETE - Function Views (Django REST framework)
17:45
The selfish The Joker was taught a lesson by Officer Rabbit. #funny #supersiblings
00:12
Как мы играем в игры 😂
00:20
МЯТНАЯ ФАНТА
Рет қаралды 3,3 МЛН
Spongebob ate Patrick 😱 #meme #spongebob #gmod
00:15
Mr. LoLo
Рет қаралды 20 МЛН
Офицер, я всё объясню
01:00
История одного вокалиста
Рет қаралды 5 МЛН
Django Rest Framework API #22 / Many To Many Relationship , Nested Data
31:20
ViewSets in Django Rest Framework and Types #10
13:26
IamPython
Рет қаралды 11 М.
Django Rest Framework API #16 / Many To One Relationship, Nested Data
20:46
Django Rest Framework | Serializers & CRUD
22:40
Dennis Ivy
Рет қаралды 387 М.
Django & React Tutorial #5 - Handling POST Requests (Django REST)
17:30
Django Rest Framework Series - Filters and Search features  - Part-6
38:41
The selfish The Joker was taught a lesson by Officer Rabbit. #funny #supersiblings
00:12