Django REST Framework Model Relationships

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ก.ย. 2024

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

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

    Join my free course on building a Todo API with Django REST Framework: prettyprinted.com/djangotodoapi

  • @juandiegocastanogomez3854
    @juandiegocastanogomez3854 4 ปีที่แล้ว +7

    Single Handedly the BEST video series on Django Rest Framework I've ever seen, and seen them all on TH-cam, Udemy, etc. Concise, technical but just enough vanilla. Can't fully express my gratitude. This tutorial is so good that even though I have a student budget (haha) Iḿ really considering buying your courses. PERFECT!

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

      True, this is the core and wasted some 40 hours in udemy.

    • @SatyamSingh-hz9su
      @SatyamSingh-hz9su 3 ปีที่แล้ว

      Can you drop the playlist link

  • @Iamkabera
    @Iamkabera 4 ปีที่แล้ว +2

    Two years late, but this is one of the most useful resources I have come across.

  • @swadhikarc7858
    @swadhikarc7858 5 ปีที่แล้ว +6

    Awesome explanation. To those who get 'rest_framework.serializers' has no attribute 'HyperLinkedModelSerializer' error, this is due to the ModelSerializer itself handles the hyperlink url in the latest versions of rest_framework.
    Therefore, in the serializer class, you may inherit from ModelSerializer itself like class ParadigmSerializer(serializers.ModelSerializer):

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

      Thanks!

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

      ModelSerializer seems to bring the urls for its own model and will not work for fields such as ForeignKey which are mentioned in a different model.

  • @bcaclassesnepal1992
    @bcaclassesnepal1992 11 หลายเดือนก่อน

    Thank you for this please keep on posting great videos like these.

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

    Watched so many drf related videos, no one was as clear as you.

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

    You might not know it! But you saved me a lot of research on my bachelor project, thanks a lot

  • @gaikwadabhishek
    @gaikwadabhishek 6 ปีที่แล้ว +11

    Hi, I love your Django Series. I'm not able to understand how to use authentication and authorization with Rest framework. Can you please help me with that!

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

    Thanks a lot man...
    Lots of love from India

  • @geoafrikana
    @geoafrikana 2 ปีที่แล้ว

    Thanks for this useful explanation.

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

    Please make a course on your website about Django Rest Framework, including as much as you can... I'd buy it definitely.

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

      That's part of the plan. Hopefully I get to it within the next few months.

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

    Hi..... you are just awesome, one of the best explanation in youtube on REST FRAMEWORK.... thanks a lot

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

      You're welcome! Thanks for watching!

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

    Great man, keep continues excelent videos, thanks.

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

      I won't stop! Thanks for watching.

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

    It is so assuring to see someone else is having problem with typing serializers too. I feel you bro. 8:03

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

      lol! I'm terrible at typing words I never use outside of programming.

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

    wowww, great work, amazing, huge thanks

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

    You're awesome man 🙌

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

    Hi, I liked your video. I have a question for you. Based on the above example that you have shown, instead of many to many relationships, one to many relations works more good right? Because its also like one programmer can have multiple languages

  • @ZainAli-me4qk
    @ZainAli-me4qk 4 ปีที่แล้ว

    Thanks man for great tutorial

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

    Thanks brother! For django rest framework

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

      You're welcome! Thanks for watching.

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

    Wow, this was so clear !

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

    Why the dropdown of the foreign keys of the 10:07 minute does not appear to me?
    I am using the following versions:
    Django = 3.0.4
    djangorestframework = 3.11.0
    djangorestframework-jwt = 1.11.0
    psycopg2-binary = 2.8.3 (for Postgresql)
    gunicorn = 20.0.4
    pyjwt = 1.7

    •  2 ปีที่แล้ว

      hi, I had same problem while, you have to add field to your LanguageSerializer class fields = ('id', 'url', 'name', 'paradigm')

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

    Thanks a lot for your tutorial!

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

    Again very useful - thanks.

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

    Hi,you really teach very well!Could you teach something about filter?

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

    How would you manage voters-polls, as many to many, but in a such way, that voter can do a certain poll only once? When a new poll is created, would you first immediately add all existing polls to him, and how would you set voted flag on a pivot table, so that he wouldn't be able to vote again on that particular poll. Thanks.

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

    Loving your videos you have a new subscriber!

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

      Thanks for watching and for subscribers.

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

    Thanks a lot it's helped me >.<

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

    Great video! Could you please show me how to create resources using postman or any other type of client? The browsable api sometimes seems too "magic" for me.

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

    Using your example, Could you get a list of languages based on the paridigm? Something like GET /languages?paradigm=1

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

    I kinda followed u step by step but i get an error cause of the hyperlinkedmodel........." Could not resolve URL for hyperlinked relationship using view name", why do i have this error when i have followed the same steps as he did meh

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

    If I may ask, would it be possible to views programmers tagged to each language like we have languages displayed for each programmer?

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

    can i get the link of this project api. m not geting on your github or any below link.

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

    I get Assertion error, after adding ForeignKey, "should either include a `serializer_class` attribute, or override the `get_serializer_class()` method." what should i do?

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

    Amazing!

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

    How do i change the colour of my api ..? Any idea !

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

    is there a way to print the language name when viewing the programmer? Rather than the language id or url?

  • @PhucNguyen-bn9io
    @PhucNguyen-bn9io 5 ปีที่แล้ว

    Thanks for your videos ^^

  • @serhii.chumachenko
    @serhii.chumachenko 6 ปีที่แล้ว

    Nice job! Thanks!

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

      You're welcome! Thanks for watching.

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

    How t add status code and a message to the output json array

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

    And if I want to show the name of the language and its paradigm in programmers?

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

    if there will be 2 k languages, how to make pagination on it?

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

      I'll probably make a video to cover this, but check this out: www.django-rest-framework.org/api-guide/pagination/

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

      pagination inside json item?
      {
      'album_name': 'The Grey Album',
      'artist': 'Danger Mouse'
      'tracks': [
      {'title': 'Public Service Announcement'},
      {'title': 'What More Can I Say'},
      {'title': 'Encore'},
      ............ 1k
      ],
      }

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

    Hey, Anthony, good video here! :) thanks. Can you make me understand when I must to set _on_delete_ param to CASCADE or PROTECT or something else? What are they doing? What’s choosing? More usage example are welcome (and good idea for next episode, btw)

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

      I'll make a video for that.
      But basically the idea to prevent invalid data. If you delete a part row, you must consider what happens to its children, and on_delete helps you with that. CASCADE simply deletes all the children. PROTECT stops you from deleting a parent when children exists.

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

    Hi, I would just like to ask why my languages field in th-cam.com/video/QB9gGEwxxM4/w-d-xo.html is not showing and just the Name field?
    Awesome video by the way!!

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

    I'm having an issue: instead of using sqlite3 I am using postgres, however whenever I try to use the MyModel.objects.all() it simply states that my model does not have a property or method named objects.

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

      What is the exact error text?

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

    Thank you! Your tutorials are great. Is there a way to change the hyperlink for the user to still take you to the user, but SHOW the username? Or show the language names known by each user? make it more human readable?
    i.e Bob/

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

      Good question. Can you please give the answer of your own question?

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

    Nice tuts! Can you please make videos on django AWS dynamodb?

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

      I'll add that to my list. Thanks for the idea.

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

    Can you make a video about overriding create and update for nested serializers?

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

      I'll consider that. Thanks for the idea.

  • @testtest-xg4bf
    @testtest-xg4bf 2 ปีที่แล้ว

    от души братан

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

    Thanks for the very helpful videos!
    I'm working on a page it has a form and inside it has many comboboxes containing data from each tables, I created for each table in my database a serializer class and a view to retrieve data from each tables, the problem is while I load this form page it takes a while to load. So i'm guessing if there's a way to join unrelated models

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

      Maybe select_related or prefetch_related can help you.

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

    shouldn't be the languages not urls , but instead the object properties of the languages.
    so in a front-end app. we're going to fetch those urls 3x instead of 1?
    I think its better to have something like this
    {
    "languages":[
    {"id":1,
    "name":"Java",
    "paradigm":{"id":1,"name":"OOP"}
    }
    ]
    }

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

    thanks for the great series of tutorial . but one question what will happen if we want to add a many to many between 2 models and some how make a third model for making the relation between them ??

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

      I don't understand what you mean. Are you trying to use the third model as the model that will hold the data from both tables, or do you want a third table to related to one of the first two in some way?

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

      @@prettyprinted actually yes third table to join the other 2 tables in laravel we call it pivot table and its responsible for many yo many relationships :)

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

      @@farshadbadiee7133 What Laravel calls a pivot table Django does automatically. Since pivot tables are very simple, there's need to specify them directly in Django.

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

      @@prettyprinted Thanks For great answer do you have any plan to make any toturial about many to many realtionships ?

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

      @@farshadbadiee7133 I will eventually.

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

    I can't read the code

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

    is there any way to add a non-model field in the serializer.

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

      You should be able to, but I haven't tried it yet. You may have to override the to_representation method. www.django-rest-framework.org/api-guide/serializers/#to_representationself-obj

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

    hi love your videos. i have a question. how would you handle a self referencing model with a many to many relationship?

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

      You use quotes. Like this: stackoverflow.com/questions/15285626/django-self-referential-foreign-key

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

      @@prettyprinted Thanks once again. While this is very helpful for me and is what i might actually redirect to, however, i was looking as something like this that has many relationships e.g custommodel = models.ManyToManyField('self', through='JoiningTable', symetrical=False). Django doesnt populate the joining table or how do i get to do that with the api.

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

      @@prettyprinted Also while trying that option, will i allow null=True ? especially for records that dont have a parent_id

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

      @@maxennybee Yeah, if you don't expect each record to have parent, then you want null to be True.

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

    nice, would you like to share some complex example ?. thanks in advance

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

      I definitely will make more complicated examples in the future.

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

    Can you please help me with Authentication and Authorization with Django Rest Framework?

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

      Videos on that are coming soon.

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

    This was a good video, but it lacked practical use, such as making actual api calls on an application, even if a simple one, to demonstrate these concepts better.

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

      I'll consider making more realistic examples for this.

  • @skyblaze6687
    @skyblaze6687 2 ปีที่แล้ว

    dude it totally stupid part of video better u should remove
    two model table api cant work their (imagine if u create 3 and have instances different id ) probably when u click on api pk value it open on different id just assume id save differently foreignkey doesnt help u to give different id for exact model table