Django REST Framework Model Relationships

Поделиться
HTML-код
  • Опубликовано: 10 сен 2024

Комментарии • 97

  • @prettyprinted
    @prettyprinted  4 года назад +1

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

  • @Iamkabera
    @Iamkabera 4 года назад +2

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

  • @juandiegocastanogomez3854
    @juandiegocastanogomez3854 4 года назад +7

    Single Handedly the BEST video series on Django Rest Framework I've ever seen, and seen them all on RUclips, 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

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

  • @kiranpaithane3278
    @kiranpaithane3278 4 года назад

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

  • @geoafrikana
    @geoafrikana 2 года назад

    Thanks for this useful explanation.

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

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

  • @vinodsagar2412
    @vinodsagar2412 5 лет назад

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

  • @jhoanmartinezsilva2609
    @jhoanmartinezsilva2609 3 года назад

    wowww, great work, amazing, huge thanks

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

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

  • @ZainAli-me4qk
    @ZainAli-me4qk 4 года назад

    Thanks man for great tutorial

  •  6 лет назад +1

    Great man, keep continues excelent videos, thanks.

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

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

  • @akshaychauhan545
    @akshaychauhan545 3 года назад

    You're awesome man 🙌

  • @rahulvanmali1406
    @rahulvanmali1406 6 лет назад +1

    Thanks brother! For django rest framework

  • @o___o4597
    @o___o4597 4 года назад

    Thanks a lot for your tutorial!

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

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

  • @wechulipaul
    @wechulipaul 4 года назад

    Wow, this was so clear !

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

  • @vinayaksinghsendhaw8903
    @vinayaksinghsendhaw8903 3 года назад

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

  • @iancarr3923
    @iancarr3923 5 лет назад

    Again very useful - thanks.

  • @michaels973
    @michaels973 4 года назад

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

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

  • @kristoffergonzaga5531
    @kristoffergonzaga5531 5 лет назад +1

    Hi, I would just like to ask why my languages field in ruclips.net/video/QB9gGEwxxM4/видео.html is not showing and just the Name field?
    Awesome video by the way!!

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

  • @moltenaluminium
    @moltenaluminium 4 года назад

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

  • @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
      ],
      }

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

  • @PhuongPhan
    @PhuongPhan 6 лет назад

    Loving your videos you have a new subscriber!

    • @prettyprinted
      @prettyprinted  6 лет назад

      Thanks for watching and for subscribers.

  • @leewilliam8606
    @leewilliam8606 6 лет назад

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

  • @ALXG
    @ALXG 4 года назад

    Amazing!

  • @serhii.chumachenko
    @serhii.chumachenko 6 лет назад

    Nice job! Thanks!

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

  • @PhucNguyen-bn9io
    @PhucNguyen-bn9io 5 лет назад

    Thanks for your videos ^^

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

  • @testtest-xg4bf
    @testtest-xg4bf 2 года назад

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

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

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

  • @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"}
    }
    ]
    }

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

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

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

  • @ivonherms
    @ivonherms 4 года назад

    I can't read the code

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

  • @tejasgajare542
    @tejasgajare542 6 лет назад

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

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

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