10 | Nested serializer for Create and update data in Django Rest Framework | by Hardik Patel

  Рет қаралды 63,967

Hardik Patel

Hardik Patel

Күн бұрын

How to get data for nested fields?
How to create, update nested field data using nested serializer?
Links -
Django rest auth - django-rest-aut...
Source Code - github.com/aar...
Important Books: -
Django 4 by example - amzn.to/3ymjjxD
Gears:
Microphone - T669-Condenser-Microphone-Adjustable-Scissor - amzn.to/3WB0XCs
Previous Microphone - Boya ByM1 - amzn.to/3Yc17Bv
Laptop - Mac book Pro M2 - amzn.to/46zEOIh
(Used in few videos to record in some it is used to edit videos)

Пікірлер: 72
@rembautimes8808
@rembautimes8808 3 жыл бұрын
This is a good tutorial, well worth the 30 min investment. There is gain of knowledge by min 15.
@pinniramakrishna2467
@pinniramakrishna2467 6 жыл бұрын
Thanks you very much for your classes. I learnt a lot from your django and REST API classes. Please continue your videos Thanks you
@rahulsinghdhek
@rahulsinghdhek 5 жыл бұрын
Hello Aarav, Can you cover create/update of Many to many relationship where an associative table(3rd table) holds the relation of two tables. I am good with creating(POST) but facing hard time while updating. Gone through many stackoverflow questions as well , didn't help. A small example or any authentic website/link where I could find the Update of associative table. Thanks
@philipmutua
@philipmutua 5 жыл бұрын
Thank you very much for the video. You have no idea how this has helped me alot! I had a problem with updating complex nested items ,with your tutorial now I'm good.
@manikraichurakar4529
@manikraichurakar4529 4 жыл бұрын
u r Don sir.... really thnx , even django docs also has no knowledge..
@tmacfan1992
@tmacfan1992 5 жыл бұрын
Very thought through example, i find myself revisiting this video periodically
@thiagobueno3486
@thiagobueno3486 4 жыл бұрын
Me too haha
@tz2014
@tz2014 2 жыл бұрын
Appreciate Hardik for this amazing tutorial on DRF. id field in choices is ignore without doing like you did, it worked but I couldn't figure out why ?
@TahaKhan-tm7rh
@TahaKhan-tm7rh 3 жыл бұрын
You Sir are a genius. Thanks a ton for uploading this video.
@alexandergarzo9415
@alexandergarzo9415 2 жыл бұрын
Thanks for this tutorial, very helpful!
@adithyanps8178
@adithyanps8178 5 жыл бұрын
thank you so much ..really you saved my lot of time... sir, can you make a video about double nested serializer....
@thiagobueno3486
@thiagobueno3486 4 жыл бұрын
I`m trying undesrtand better double nasted serializer... find you something? Thanks
@thalariharsha
@thalariharsha 3 жыл бұрын
Please do more help full
@kousiksekar1894
@kousiksekar1894 4 жыл бұрын
Very informative and useful content, Thanks for the post
@vivekascoder
@vivekascoder 4 жыл бұрын
I become you fan sir, your videos are amazing.
@tanimsk
@tanimsk 11 ай бұрын
Thank you so much! very helpful!
@elmehdilamrhari9181
@elmehdilamrhari9181 6 жыл бұрын
thank you so much really you helped me with the "depth=1" :)
@rameshyelle2884
@rameshyelle2884 3 жыл бұрын
Thank you so much for sharing knowledge.
@brwaata3001
@brwaata3001 5 жыл бұрын
that was great you saved me in many problem
@muruganraja9
@muruganraja9 3 жыл бұрын
Nice video sir, can you upload annotate and aggregate concep witj django...
@aravindor
@aravindor 4 жыл бұрын
Great tutorial 👍... Quentin Tarantino django in video tags 😂😂😂..
@mohamadsajedi5857
@mohamadsajedi5857 4 жыл бұрын
You really help me my friend.... Thank You .Best Regards
@ahm3drn
@ahm3drn 5 жыл бұрын
Thank You that's perfect
@jesusandrescabrerasuarez1636
@jesusandrescabrerasuarez1636 4 жыл бұрын
excellent bro!!! thank you so much
@tejasmandre666
@tejasmandre666 4 жыл бұрын
Thankyou for making this!
@DirtySouth33T
@DirtySouth33T 3 жыл бұрын
Great video, one question. How would you handle unique constraints with nested When trying to update or create I receive Software with this Software Name already exists, or Server with this Server Name already exists. How would you handle this? I have 2 models Software name unique=true slug Server name unique=true slug software m2m(Software)
@bhaaratsingh5595
@bhaaratsingh5595 6 жыл бұрын
Nice video.
@nusk003
@nusk003 5 жыл бұрын
Hello sir, thank you so much for the tutorial and I have a question... How to upload files or multipart content in drf??
@dennysam829
@dennysam829 5 жыл бұрын
This was so good!!
@saarpathak2422
@saarpathak2422 4 жыл бұрын
Hi, Aarav I am trying a similar solution. But getting MainInventory() got an unexpected keyword argument 'group'. class MainInventorySerializer(serializers.ModelSerializer): class Meta: model = MainInventory fields = ( 'inv_id', 'inv_name' ) class MainGroupSerializer(serializers.ModelSerializer): inv_id = MainInventorySerializer() class Meta: model = MainGroup fields = ( 'group_id', 'group_name', 'inv_id' ) def create(self, validated_data): inv_data = validated_data.pop('inv_id') group = MainGroup.objects.create(**validated_data) MainInventory.objects.create(**inv_data, group=group) return group My Model class MainInventory(models.Model): inv_id = models.IntegerField(verbose_name='INVENTORY ID', primary_key=True) inv_name = models.CharField(verbose_name='INVENTORY NAME', max_length=512) class MainGroup(models.Model): group_id = models.IntegerField(verbose_name='GROUP ID', primary_key=True) group_name = models.CharField(verbose_name='GROUP NAME', max_length=512) inv_id = models.ForeignKey(related_name='group_inv', on_delete=models.SET_NULL, to='hosts.MainInventory', blank=True, null=True)
@ranuvijay1
@ranuvijay1 3 жыл бұрын
nested serializers or joins in queryset, which one should we use for getting the data ?
@kamtanath4494
@kamtanath4494 6 жыл бұрын
Great Effort!
@dhanalm
@dhanalm 4 жыл бұрын
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.
@vinodreddy1722
@vinodreddy1722 6 жыл бұрын
Sir at 6: 40 ,here we are creating choice serializer object without passing any data to choice serializer , so how it is retrieving the data?
@niteshrawat576
@niteshrawat576 5 жыл бұрын
Choice model has fk with Question model.
@dgiri2333
@dgiri2333 4 жыл бұрын
How to do Nested Serializer for country select based on country list of States ,state select based on state list of filter district will return how to do using ....Using seralizer..
@ffiuca
@ffiuca Жыл бұрын
hi, can hou help me why depth on my serilizers not working? just return flat data of jeon
@MarquisTaylor27
@MarquisTaylor27 4 жыл бұрын
What if instead of sending "id":4, "text": "BMW", I need to just send "id":4. Since I'm doing an update not a create why do I need to re-add the choice? But if I don't get I get a valuation error? Is there anyway I can reload the choice instance before the validation?
@ІлляКадобянський
@ІлляКадобянський 2 жыл бұрын
U saved my ass, brov :)
@thalariharsha8160
@thalariharsha8160 3 жыл бұрын
sir how to craete multiple foreginkey relation fileds in single table how u do that , i am grtting error, please do one video
@deepakverma7481
@deepakverma7481 4 жыл бұрын
Thanks a lot. But, how abt carryout out CRUD operation on 'choices' alone, along with display of question on read operation? Pls help
@deepakverma7481
@deepakverma7481 4 жыл бұрын
@@HardikPatelN sir, it will be so nice if can send me example to carry out crud on choices along with questions on read
@Alliswelltoday
@Alliswelltoday 3 жыл бұрын
sir am getting error rquestion required after passing multiple choices
@hafeezshaik1221
@hafeezshaik1221 4 жыл бұрын
Hi , I am using same process with mysql database, I am getting error like this 'Countries' is an invalid keyword argument for this function, please give me solution.Thank you
@uweopfern
@uweopfern 5 жыл бұрын
I am getting this error while trying to consume add new choice model, i am being told this ```IntegrityError at /api/choices/ (1048, "Column 'question_id' cannot be null")``` when i remove depth =1 , it works but when it is there , i get that error
@sugiono2801
@sugiono2801 3 жыл бұрын
how to return a list choiches: ['bmw', 'audi'] from nested?
@sarojpaudel7479
@sarojpaudel7479 3 жыл бұрын
Thank you so much for the video sir. I have a problem. I have similar project where I have to do similar thing like above. But what i need is, I need to show only one choices (int=pk) of a question(int=pk). That means , similar endpoint like localhost/api/question/1/choices/1. how can we do that. Please help.
@sarojpaudel7479
@sarojpaudel7479 3 жыл бұрын
stackoverflow.com/questions/64640122/i-have-to-pass-the-multiple-intpk-in-a-single-endpoint-for-django-rest-api This my actual problem.
@sarojpaudel7479
@sarojpaudel7479 3 жыл бұрын
@@HardikPatelN cant we do this using GenericApiview?? do we have to use viewset?? because i am very comfortable using viewset? and what is mixins used for??
@SACHINAGARWAL16
@SACHINAGARWAL16 4 жыл бұрын
In your Question model class you have property declared returning function choice_set.() of self. I dont find choice_set in class!
@SACHINAGARWAL16
@SACHINAGARWAL16 4 жыл бұрын
@@HardikPatelN thanks for reply. I tried inserting child without properties and it worked. But I wonder that when I change property name from choice_set to anything else it complains there is no such property in Question. Have no clue
@SACHINAGARWAL16
@SACHINAGARWAL16 4 жыл бұрын
Hi.. Below is my class and error. It works all well when I use choice_set but breaks if I use anything else like below choice_set2. Not sure if this property choice_set2 should have reference anywhere else. class QuestionSerializer(serializers.ModelSerializer): choice_set2 = ChoiceSerializer(many=True) class Meta: model = Question fields = ('pub_date', 'question_text', 'choice_set2') Got AttributeError when attempting to get a value for field `choice_set2` on serializer `QuestionSerializer`. The serializer field might be named incorrectly and not match any attribute or key on the `Question` instance. Original exception text was: 'Question' object has no attribute 'choice_set2'.
@gowthamns8228
@gowthamns8228 4 жыл бұрын
Is that possible to call like this without using primary and foreign key field in models.py ?
@gowthamns8228
@gowthamns8228 4 жыл бұрын
@@HardikPatelN yeah, but i need to post the data, for example in I need to post username, email and phone from one model and address line, postcode etc from another model, from a single api, so i dont have any idea, but your code is telling something to me... so i don`t want to use many = True then its a right way?
@gowthamns8228
@gowthamns8228 4 жыл бұрын
how to join two tables in serializer and perform crud operation(not a multiple inheritance)?
@gowthamns8228
@gowthamns8228 4 жыл бұрын
@@HardikPatelN yeah but I don't have any idea about custom validation and all.. i need some more help or how the code will be like... Any idea or any source?
@vikaskachwaya438
@vikaskachwaya438 5 жыл бұрын
how to update multiple fields of model at single request.
@manikraichurakar4529
@manikraichurakar4529 4 жыл бұрын
TypeError: Direct assignment to the reverse side of a many-to-many set is prohibited. Use reportsTo.set() instead. can anybody tell the solution
@dgiri2333
@dgiri2333 5 жыл бұрын
Hi how to create nested serializer like if select district then it's show model list ,if model select all village can show on villages how to implement
@dgiri2333
@dgiri2333 5 жыл бұрын
@@HardikPatelNgive me your mail I'd
@dgiri2333
@dgiri2333 5 жыл бұрын
@@HardikPatelN I don't get you
@shreerangaraju1013
@shreerangaraju1013 5 жыл бұрын
instance.choices.remove(instance.choices.get(id=choice.id)) instead of choice.delete().
@shreerangaraju1013
@shreerangaraju1013 5 жыл бұрын
@@HardikPatelN Thank you
@yashsoni1100
@yashsoni1100 5 жыл бұрын
Choice is not in #jocking
@jesusandrescabrerasuarez1636
@jesusandrescabrerasuarez1636 4 жыл бұрын
hey buddy, i need to store json array using ModelViewSet class.. everybody tells "you must override the update method", but i cant figure out how to solve it... i need some help to get on the way.. Can you help me bro? twitter: @jacsdev
@jesusandrescabrerasuarez1636
@jesusandrescabrerasuarez1636 4 жыл бұрын
@@HardikPatelN i find a nice way to solve it, i just change a little the update method in viewsetmodel n then added this line: serializer = self.get_serializer(data=request.data, many=isinstance(request.data, list)) now, i can to invoke "put method" (update) with a json array and it works like a charm!... Thanks for your feedback bro.
Django Rest Framework API #16 / Many To One Relationship, Nested Data
20:46
Стойкость Фёдора поразила всех!
00:58
МИНУС БАЛЛ
Рет қаралды 6 МЛН
Win This Dodgeball Game or DIE…
00:36
Alan Chikin Chow
Рет қаралды 43 МЛН
Watermelon magic box! #shorts by Leisi Crazy
00:20
Leisi Crazy
Рет қаралды 80 МЛН
3 | Serializations in Django Rest Framework | By Hardik Patel
25:50
Django REST Framework Generic Views
34:22
Bryan Brkic
Рет қаралды 2,3 М.
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 М.
How To Make a Django REST API - Full Tutorial & Deployment
40:18
Tech With Tim
Рет қаралды 86 М.
This is apparently the most loved CRUD app of 2023
19:38
Dreams of Code
Рет қаралды 130 М.
Django Rest Framework | Serializers & CRUD
22:40
Dennis Ivy
Рет қаралды 388 М.
Python Django REST API In 30 Minutes - Django Tutorial
30:42
PedroTech
Рет қаралды 19 М.
Стойкость Фёдора поразила всех!
00:58
МИНУС БАЛЛ
Рет қаралды 6 МЛН