Thanks Ajeet, please check the Django REST Framework playlist , I’m sure you will find a lot to learn from : th-cam.com/play/PLmDLs7JbXWNjr5vyJhfGu69sowgIUl8z5.html
I know that this isn’t the forum for this and beginners don’t need philosophy... but postman is a GUI for manual testing. It won’t scale. It won’t catch bugs. I use postman instead of a browser I guess but I try to get away from it. The problem is that books and tutorials don’t focus on automated testing which is going to do many positive things for a project. In all tutorials like this, there is some section where the teacher asserts that the output is correct with their human eyes. This is not needed. A computer can read JSON. You can teach it what “right” is. Measure it with a non human sensor like science. Then tools and culture would move that way and it would be less mysterious how to build stuff that works, can be refactored, does not have upgrade regressions or more things like this that testing touches on.
Thanks Chris for sharing your thoughts, and I totally agree with you , therefore I’m preparing a tutorial for API testing. But for the purpose of understanding the basics, how relationships work and what the developers should expect to see as responses or how the request data should look like, postman comes really handy as keeping things simple helps beginners understand the concept.
Great vids, I absolutely love it and think that it's best django tutorial on youtube. Yet, on small remark - you won't have to write all your model fields in serialization if you use *fields = '__all__'*
Thank you Denis 🙂, and yes you are 100% right about the fields and to be honest, a few weeks ago I was thinking about the same thing, like why I keep writing the whole fields lol, but I still didn’t find a reason for that🤷🏻♂️, maybe I’m not lazy enough 😅
Super awesome! Query: I am trying to retrieve the list (in this example, car plan) to angular input, can you share any reference material for the same?
Sorry for the delay, I was sick. You don't have to use the plan's ID, you can simply use the plan name while creating a new object, but before that you need to edit the create function in the views.py file: just replace car_plan=CarPlan.objects.get(id=car_data["car_plan"]) with car_plan=CarPlan.objects.get(plan_name=car_data["car_plan"]). Thanks.
Hi Code Environment. I've got a question: How can I tell my serializer to only display certain fields from the foreign key reference? In this case just returning car plan id and car plan name?
Hi sir. I have a issue here. For me it is getting displayed as car_plan = null whereas in your case the corresponding id is rendered. How to solve this?
In apiview, am able to see all the details (including one toone related field details) but when I am trying to post the details there is no drop down field to set the other model object. I have included the all the fields including other model name in the serializer field attribute. Please help me on this
Hi.. this is helpful. Can you also explain how we can display CarSpec details inside each CarPlan. In other words how can we see list of different CarSpecs available under each CarPlan in API
Thank you, one of the approaches is to add an extra field in the CarPlan serializer using a function that will get the CarSpecs objects related to the fetched CarPlan object. You can also use ManyToMany relationship in the CarPlan model to link multiple CarSpecs objects, see this video: th-cam.com/video/nB1MczHlweA/w-d-xo.html
Very interesting though you are not focusing on the main subject of your video which title is 'Many To One Relationship'. And it remains a little bit unclear for me. Tell me if i am wrong: One CarPlan can have Many CarSpecs. but: One CarSpecs can only have One CarPlan. So should'nt it be a One to One relationship ? If I have a class Car and a class User. A User can have Many Cars. But One Car can only have One User. If I set a models.foreignKey(User, on_delete=SET_NULL, null=True) on the car, don't I set a One to One relationship from the Car to the User? I am going to watch your video One to One relatshionnship, it may help.
I have Author and Book models.In Book model, author is foreignkey. I want to display collection of books, for each author. So I have created property function in Author model and in Author serializer, I have added books in fields... But I'm only getting Book Id. I also want all fields of Book model. Please help me
I did the same thing I think, it gave me this error IntegrityError at /transactions/2 NOT NULL constraint failed: transactions_draft.office_id inside the draft object, there is an office object. and I want to create a new draft object. I pass the id of the office in the post request but it gives me this error
@@codeenvironment So I am fetching all the data from db against one table using Get api. Say there are multiple ids and 4 fields against each id. So for multiple ids, If user wants to update any of the field from any of the id, it should be done by bulk update. How should I achieve that ? I hope the scenario is clear to you.
Let’s say you have multiple items and the user wants to update the price for 4 items then you can get all the objects: Items = Item.objects.all() Then loop through the objects and set the values for price field Item.price = new value And outside the for loop you can do the bulk update: ITem.objects.bulk_update(items, [“price”])
I have created to nested serializer, but want to customize the nested output { Col 1: data Col 2 :data Nested data {col3 : data Col 4:data }} Required: {Col1:data Col2:data Col3:data Col4:data}
How we do one to many? I need to crate endpoint for ex- Order & order_details tables create using single endpoint Json- { "User_id" : "01", "Date" : "current date", "Address" : "address" Order_details: { [ "Item_code": "01", "Quantity" : 5 ], [ "Item_code" : "02", "Quantity" : 5 ] } }
You have to override the Create / Post method in your view and send the nested or child data with your request . Check this tutorial: th-cam.com/video/NCBxyw6rDds/w-d-xo.html
@@codeenvironment Hi I have one doubt can you help me to resolve that.stackoverflow.com/questions/64008694/multi-nested-with-django-restframework-and-mongodb
thanku so much this is what i actually looking for and did not find it anywhere
Thanks Ajeet, please check the Django REST Framework playlist , I’m sure you will find a lot to learn from :
th-cam.com/play/PLmDLs7JbXWNjr5vyJhfGu69sowgIUl8z5.html
Hey Ajeet Mishra.. Let me know how to write create methods in views..Table occurred 4 foreign keys... Please suggest me..
@@LakshmanKumar-qp9xn please watch the overriding create action tutorial for that :
th-cam.com/video/4dPVywV-X84/w-d-xo.html
Thanks alot bro i was stuck almost three days and got burned out because of unknow about depth = 1 😭Thanks alot♥♥
Glad I could help 🙂👍🏻
me too
thanks a lot code environment
I know that this isn’t the forum for this and beginners don’t need philosophy... but postman is a GUI for manual testing. It won’t scale. It won’t catch bugs. I use postman instead of a browser I guess but I try to get away from it. The problem is that books and tutorials don’t focus on automated testing which is going to do many positive things for a project. In all tutorials like this, there is some section where the teacher asserts that the output is correct with their human eyes. This is not needed. A computer can read JSON. You can teach it what “right” is. Measure it with a non human sensor like science. Then tools and culture would move that way and it would be less mysterious how to build stuff that works, can be refactored, does not have upgrade regressions or more things like this that testing touches on.
Thanks Chris for sharing your thoughts, and I totally agree with you , therefore I’m preparing a tutorial for API testing. But for the purpose of understanding the basics, how relationships work and what the developers should expect to see as responses or how the request data should look like, postman comes really handy as keeping things simple helps beginners understand the concept.
I'm loving this guy more and more
Thank you so much, this video helps me alot !!!
Very convenient, thank you very much
Very useful info on Django, great work!
good job man. I like your teaching style.
Thank you Amir 👍🏻
Exactly what I was looking for. Thank you so much!!
Glad I could help!
Hey Man, you've helped me out with this video. Thankyou, big time!
I’m glad I could help ✌🏻
Great vids, I absolutely love it and think that it's best django tutorial on youtube. Yet, on small remark - you won't have to write all your model fields in serialization if you use *fields = '__all__'*
Thank you Denis 🙂, and yes you are 100% right about the fields and to be honest, a few weeks ago I was thinking about the same thing, like why I keep writing the whole fields lol, but I still didn’t find a reason for that🤷🏻♂️, maybe I’m not lazy enough 😅
Super awesome! Query: I am trying to retrieve the list (in this example, car plan) to angular input, can you share any reference material for the same?
Plz anyone tell me this. This great but how can a user know that is id is for this plan while creating a new object.
Sorry for the delay, I was sick. You don't have to use the plan's ID, you can simply use the plan name while creating a new object, but before that you need to edit the create function in the views.py file:
just replace car_plan=CarPlan.objects.get(id=car_data["car_plan"]) with car_plan=CarPlan.objects.get(plan_name=car_data["car_plan"]).
Thanks.
@@codeenvironment and thanks a lot for the answer ! You are awesome.
Nice question.
Hi Code Environment. I've got a question: How can I tell my serializer to only display certain fields from the foreign key reference? In this case just returning car plan id and car plan name?
You can use something called www.django-rest-framework.org/api-guide/relations/#custom-relational-fields
Hi sir. I have a issue here. For me it is getting displayed as car_plan = null whereas in your case the corresponding id is rendered. How to solve this?
depth = 1 mind blowing for me thanks
I agree, it’s magical👌🏻
In apiview, am able to see all the details (including one toone related field details) but when I am trying to post the details there is no drop down field to set the other model object. I have included the all the fields including other model name in the serializer field attribute. Please help me on this
Could please share the code with me at:
Codes.environment@gmail.com
what about one to many, how do i want the response to the carplan along with a list of the corresponding carspecs (sorry, my english is not good)
Hi.. this is helpful. Can you also explain how we can display CarSpec details inside each CarPlan. In other words how can we see list of different CarSpecs available under each CarPlan in API
Thank you, one of the approaches is to add an extra field in the CarPlan serializer using a function that will get the CarSpecs objects related to the fetched CarPlan object.
You can also use ManyToMany relationship in the CarPlan model to link multiple CarSpecs objects, see this video:
th-cam.com/video/nB1MczHlweA/w-d-xo.html
Very interesting though you are not focusing on the main subject of your video which title is 'Many To One Relationship'. And it remains a little bit unclear for me.
Tell me if i am wrong:
One CarPlan can have Many CarSpecs.
but: One CarSpecs can only have One CarPlan.
So should'nt it be a One to One relationship ?
If I have a class Car and a class User.
A User can have Many Cars.
But One Car can only have One User.
If I set a models.foreignKey(User, on_delete=SET_NULL, null=True) on the car, don't I set a One to One relationship from the Car to the User?
I am going to watch your video One to One relatshionnship, it may help.
Hello RC, please check the intro of this tutorial, it might help clear things up:
th-cam.com/video/NCBxyw6rDds/w-d-xo.html
Great tutorial tks. And if there are more than one car plan per car ? how can i setup the models ?
I have Author and Book models.In Book model, author is foreignkey. I want to display collection of books, for each author.
So I have created property function in Author model and in Author serializer, I have added books in fields... But I'm only getting Book Id. I also want all fields of Book model. Please help me
I have also tried this
books = BookSerializer(many=True)
books is related_ name of author foreign key field in Book model
Hello Dhana, can you please send me an email at: codes.environment@gmail.com
Thanks
@@codeenvironment please check your inbox. Thank you
hii.. when i use postman for post so it gave error 400bad request but i fallow you... so what i do.. for post request..
Make sure all the parameters you are sending are named currently and make sure you have a forward slash / at the end of your url
@@codeenvironment i try all the way still same
Please email me at codes.environment@gmail.com,
And I’ll have a look at your code
osm video ........a big thumbs up
Thank you :)
I did the same thing I think, it gave me this error
IntegrityError at /transactions/2
NOT NULL constraint failed: transactions_draft.office_id
inside the draft object, there is an office object. and I want to create a new draft object. I pass the id of the office in the post request but it gives me this error
Hello Amir, could you please send me the code at: codes.environment@gmail.com
I’ll check it out and get back to you as soon as possible.
How can i perform bulk update in Django Rest Framework ? Can you plz help me with it ?
Can you please explain more to me what are you trying to achieve in bulk
@@codeenvironment So I am fetching all the data from db against one table using Get api. Say there are multiple ids and 4 fields against each id. So for multiple ids, If user wants to update any of the field from any of the id, it should be done by bulk update. How should I achieve that ? I hope the scenario is clear to you.
Let’s say you have multiple items and the user wants to update the price for 4 items then you can get all the objects:
Items = Item.objects.all()
Then loop through the objects and set the values for price field
Item.price = new value
And outside the for loop you can do the bulk update:
ITem.objects.bulk_update(items, [“price”])
@@codeenvironment thank you so much !!! It's helpful.
I have created to nested serializer, but want to customize the nested output
{
Col 1: data
Col 2 :data
Nested data {col3 : data
Col 4:data }}
Required:
{Col1:data
Col2:data
Col3:data
Col4:data}
Please email me your Django App code for me to be able to help you more
Thank you
How we do one to many?
I need to crate endpoint for ex-
Order & order_details tables create using single endpoint
Json-
{
"User_id" : "01",
"Date" : "current date",
"Address" : "address"
Order_details: {
[
"Item_code": "01",
"Quantity" : 5
],
[
"Item_code" : "02",
"Quantity" : 5
]
}
}
Use ManyToMany relationship for that
Thank you. But how can I create both pedant and child table using one endpoint.
You have to override the Create / Post method in your view and send the nested or child data with your request .
Check this tutorial:
th-cam.com/video/NCBxyw6rDds/w-d-xo.html
Thank you again. I will try that.
Can you please post edit and delete method?
Do you mean a video for the [post, update, destroy] methods?
@@codeenvironment Yes
Django Rest Framework API #15 / Override Delete Action (destroy method).
th-cam.com/video/Hi3TA2pGv7Y/w-d-xo.html
Django Rest Framework API #14 / Override Create Action Inside ModelViewSet.
th-cam.com/video/4dPVywV-X84/w-d-xo.html
@@codeenvironment Hi I have one doubt can you help me to resolve that.stackoverflow.com/questions/64008694/multi-nested-with-django-restframework-and-mongodb
Request For update broo
Hello Geri, please explain your request more , thanks.
You started your explanation from a very top-level, displayed code even before explaining what you wanted to achieve. smh
+++