Django Rest Framework API #14 / Override Create Action | CREATE Method ModelViewSet.

  Рет қаралды 13,028

Code Environment

Code Environment

Күн бұрын

How to override (CREATE) action inside django rest framework ModelViewSet /ModelSerializer Create Method
.
How to read the data that was sent through a post request using (request) argument then create an object and save it in the database.
Source code: github.com/CodeEnvironment/dj...
Override Delete Action (destroy method) DELETE Request:
• Django Rest Framework ...
ModelViewset With Serializer and Router:
• Django Rest Framework ...

Пікірлер: 28
@midhunskani
@midhunskani Жыл бұрын
we can do this in much more simple way def create(self, request, *args, **kwargs): serializer = serializers.BrandSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) Hope this helps. Thanks for tutorials
@10thcode
@10thcode Жыл бұрын
saved my day
@stevesteve619
@stevesteve619 4 жыл бұрын
Great and very helpful video, I’m looking forward for more.
@MaltheHave
@MaltheHave 4 жыл бұрын
Thank you for this video (:
@anton-r
@anton-r 3 жыл бұрын
tnx. super great BUT if you have an model serializer , use it to validate and save data that you got from request !
@krystlcrtz
@krystlcrtz 2 жыл бұрын
Thank you for this comment, it helped me decide whether to override viewset or serializer create
@think-dotest2166
@think-dotest2166 4 жыл бұрын
Thank you, this video helped me in my project
@codeenvironment
@codeenvironment 4 жыл бұрын
Glad it helped!
@francois-xaviercao7187
@francois-xaviercao7187 4 жыл бұрын
Thanks for the video, it helped me :)
@codeenvironment
@codeenvironment 4 жыл бұрын
Glad it helped!
@nguyenconghuy3847
@nguyenconghuy3847 2 жыл бұрын
ty
@amirhosseinebneroomi7280
@amirhosseinebneroomi7280 3 жыл бұрын
you're doing great
@codeenvironment
@codeenvironment 3 жыл бұрын
Thanks Amir
@anishghosh420
@anishghosh420 2 жыл бұрын
hey first of all your videos are great to understand how a django api works. I've been following and executing the django api for car specs till this video and i cannot move forward because i'm facing an issue i.e. when i put depth =1, the field on the running server does not appear and when i dont put any depth, the field appears and i select one of the options for my entries and perform POST but when i GET the entry values, the car_plan field is null always, it doesnt change no matter what i do. Please help me clear this so that i can move on to the next stages
@codeenvironment
@codeenvironment 2 жыл бұрын
Thank you Anish, When you choose to override create action/ method, you have to handle creating the nested object yourself, and when you use the depth variable the DRF form excludes the nested field therefore you should use a third party software like Postman or VSCode to test the API endpoints. Hope that helps you moving forward.
@dodokwak
@dodokwak 3 жыл бұрын
Does it matter much whether we override perform_create or create function? Thx.
@codeenvironment
@codeenvironment 3 жыл бұрын
I think it won’t matter if you manage to call it when you need it but as a best practice and taking the documentation as reference, it’s better to do it in the view
@vaibhavsaxena3738
@vaibhavsaxena3738 2 жыл бұрын
why in create method Id always extra increment example: if id was 4 now when we send POST requ. new data Id will be 6 .
@codeenvironment
@codeenvironment 2 жыл бұрын
Hello Vaibhav, did mean that the id is getting incremented by 2 instead of 1 on each post request?
@vaibhavsaxena3738
@vaibhavsaxena3738 2 жыл бұрын
@@codeenvironment yes
@sarojpaudel7479
@sarojpaudel7479 3 жыл бұрын
It says django.utils.datastructures.MultiValueDictKeyError: 'user' for doing the same thing above. Can you please tell me what is the problem??
@codeenvironment
@codeenvironment 3 жыл бұрын
Sometimes you get this error if you don’t pass many = True to your serializer class
@usamakaleem8378
@usamakaleem8378 3 жыл бұрын
didnt make on update
@codeenvironment
@codeenvironment 3 жыл бұрын
Hello Usama, I’m preparing a tutorial for the update method make sure you subscribe to get motivated.
@usamakaleem8378
@usamakaleem8378 3 жыл бұрын
Thanks man for.the rply so fast
@codeenvironment
@codeenvironment 3 жыл бұрын
Sorry I meant *to get notified
@codeenvironment
@codeenvironment 3 жыл бұрын
Django Rest Framework API #23 / Override UPDATE | PUT Action | Method for ModelViewSet and ApiView. kzbin.info/www/bejne/qGG8kISmZ5afn6s
@yarik83men51
@yarik83men51 3 жыл бұрын
+++
Django Rest Framework API #16 / Many To One Relationship, Nested Data
20:46
DO YOU HAVE FRIENDS LIKE THIS?
00:17
dednahype
Рет қаралды 80 МЛН
Happy 4th of July 😂
00:12
Pink Shirt Girl
Рет қаралды 30 МЛН
Serializers (Django REST framework)
6:30
CodingWithMitch
Рет қаралды 113 М.
Django DRF Project | Implimenting DRF Viewsets | 16
7:17
Very Academy
Рет қаралды 7 М.
Django Rest Framework API #22 / Many To Many Relationship , Nested Data
31:20
Airflow DAG: Coding your first DAG for Beginners
20:31
Data with Marc
Рет қаралды 215 М.
DO YOU HAVE FRIENDS LIKE THIS?
00:17
dednahype
Рет қаралды 80 МЛН