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

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ธ.ค. 2024

ความคิดเห็น • 72

  • @rembautimes8808
    @rembautimes8808 3 ปีที่แล้ว

    This is a good tutorial, well worth the 30 min investment. There is gain of knowledge by min 15.

  • @rahulsinghdhek
    @rahulsinghdhek 6 ปีที่แล้ว +10

    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.

  • @pinniramakrishna2467
    @pinniramakrishna2467 6 ปีที่แล้ว +1

    Thanks you very much for your classes.
    I learnt a lot from your django and REST API classes.
    Please continue your videos
    Thanks you

  • @manikraichurakar4529
    @manikraichurakar4529 4 ปีที่แล้ว +1

    u r Don sir.... really thnx , even django docs also has no knowledge..

  • @tanimsk
    @tanimsk ปีที่แล้ว +1

    Thank you so much! very helpful!

  • @tmacfan1992
    @tmacfan1992 5 ปีที่แล้ว

    Very thought through example, i find myself revisiting this video periodically

  • @alexandergarzo9415
    @alexandergarzo9415 2 ปีที่แล้ว +1

    Thanks for this tutorial, very helpful!

  • @TahaKhan-tm7rh
    @TahaKhan-tm7rh 4 ปีที่แล้ว

    You Sir are a genius. Thanks a ton for uploading this video.

  • @kousiksekar1894
    @kousiksekar1894 4 ปีที่แล้ว

    Very informative and useful content, Thanks for the post

  • @vivekascoder
    @vivekascoder 4 ปีที่แล้ว

    I become you fan sir, your videos are amazing.

  • @elmehdilamrhari9181
    @elmehdilamrhari9181 6 ปีที่แล้ว +3

    thank you so much really you helped me with the "depth=1" :)

  • @aravindor
    @aravindor 5 ปีที่แล้ว

    Great tutorial 👍...
    Quentin Tarantino django in video tags 😂😂😂..

  • @rameshyelle2884
    @rameshyelle2884 3 ปีที่แล้ว

    Thank you so much for sharing knowledge.

  • @ІлляКадобянський
    @ІлляКадобянський 2 ปีที่แล้ว +2

    U saved my ass, brov :)

  • @brwaata3001
    @brwaata3001 5 ปีที่แล้ว

    that was great you saved me in many problem

  • @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 ?

  • @muruganraja9
    @muruganraja9 3 ปีที่แล้ว +1

    Nice video sir, can you upload annotate and aggregate concep witj django...

  • @ranuvijay1
    @ranuvijay1 4 ปีที่แล้ว

    nested serializers or joins in queryset, which one should we use for getting the data ?

  • @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?

  • @adithyanps8178
    @adithyanps8178 5 ปีที่แล้ว +2

    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

  • @jesusandrescabrerasuarez1636
    @jesusandrescabrerasuarez1636 4 ปีที่แล้ว

    excellent bro!!! thank you so much

  • @tejasmandre666
    @tejasmandre666 4 ปีที่แล้ว

    Thankyou for making this!

  • @vinodreddy1722
    @vinodreddy1722 6 ปีที่แล้ว +1

    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 6 ปีที่แล้ว

      Choice model has fk with Question model.

  • @bhaaratsingh5595
    @bhaaratsingh5595 6 ปีที่แล้ว +2

    Nice video.

  • @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.

  • @nusk003
    @nusk003 6 ปีที่แล้ว

    Hello sir, thank you so much for the tutorial and I have a question... How to upload files or multipart content in drf??

  • @mohamadsajedi5857
    @mohamadsajedi5857 4 ปีที่แล้ว

    You really help me my friend.... Thank You .Best Regards

  • @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..

  • @dennysam829
    @dennysam829 5 ปีที่แล้ว +1

    This was so good!!

  • @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)

  • @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)

  • @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

  • @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

  • @ahm3drn
    @ahm3drn 5 ปีที่แล้ว +1

    Thank You
    that's perfect

  • @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?

  • @kamtanath4494
    @kamtanath4494 6 ปีที่แล้ว

    Great Effort!

  • @uweopfern
    @uweopfern 6 ปีที่แล้ว

    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

  • @sarojpaudel7479
    @sarojpaudel7479 4 ปีที่แล้ว

    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 4 ปีที่แล้ว

      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 4 ปีที่แล้ว

      @@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??

  • @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?

  • @Alliswelltoday
    @Alliswelltoday 3 ปีที่แล้ว

    sir am getting error rquestion required after passing multiple choices

  • @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

  • @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'.

  • @sugiono2801
    @sugiono2801 3 ปีที่แล้ว

    how to return a list choiches: ['bmw', 'audi'] from nested?

  • @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

  • @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

  • @vikaskachwaya438
    @vikaskachwaya438 5 ปีที่แล้ว

    how to update multiple fields of model at single request.

  • @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.

  • @shreerangaraju1013
    @shreerangaraju1013 5 ปีที่แล้ว

    instance.choices.remove(instance.choices.get(id=choice.id)) instead of choice.delete().

  • @yashsoni1100
    @yashsoni1100 5 ปีที่แล้ว

    Choice is not in #jocking