Django Rest Framework API #19 / One To One Relationship, Nested Data

  Рет қаралды 7,651

Code Environment

Code Environment

Күн бұрын

Django Rest Framework API #19,You Will Learn:
1- How to link two models using One To One relationship.
2- How get and show the nested data from the API response.
3- How to get the instance of the object that represent the nested data and save it by overriding the Create Action.
🎧 Music : • Study music | Programm...
Music Channel : @tuningthecode
Source code: github.com/CodeEnvironment/dj...
Override Create Action Inside ModelViewSet video:
www.youtube.com/watch?v=4dPVy...
Django Rest Framework API #22 / Many To Many Relationship , Nested Data:
• Django Rest Framework ...
Django Rest Framework API #16 / Many To One Relationship, Nested Data:
• Django Rest Framework ...

Пікірлер: 18
@harrietly4932
@harrietly4932 2 жыл бұрын
love the demo on postman where we can see the final data structure and relationship of post and rates models!
@yarik83men51
@yarik83men51 3 жыл бұрын
Thx
@muhammadehtisham2708
@muhammadehtisham2708 3 жыл бұрын
good one sir g .
@rajas6710
@rajas6710 3 жыл бұрын
Excellent
@brenoverissimo3846
@brenoverissimo3846 2 жыл бұрын
I was stuck in this part and you really helped me! Thanks!
@codeenvironment
@codeenvironment 2 жыл бұрын
I’m glad I could help 👍🏻
@zakchips
@zakchips 3 жыл бұрын
Thanks. Mostly we see OneToOne relationships in User - Profile. I use djoser to create a user object and signal to sync it with creation of a profile object. But you've shown an interesting example where we can use functionality of viewsets instead.
@codeenvironment
@codeenvironment 3 жыл бұрын
Thank you. Always try to avoid over engineering when possible.
@muhammadehtisham2708
@muhammadehtisham2708 3 жыл бұрын
very help full
@oscarparedez1417
@oscarparedez1417 3 жыл бұрын
Amazing job. Congratulations and thanks for the amazing tutorial!
@codeenvironment
@codeenvironment 3 жыл бұрын
Thank you for the support 👍🏻
@akshay_pawar10
@akshay_pawar10 2 жыл бұрын
Thank you for the wonderful tutorial. But I have a question regarding the update method, how can I update PostRate model along with Post model in same request.
@SiddiqNx
@SiddiqNx 3 жыл бұрын
Good video brother. I have a doubt. You created the PostRates model with 2 fields. Why not add the post as OneToOne field in the PostRates model? In that way we can query the PostRates model later using the post_id instead of going through the Post model. Which one will be a better design? Another doubt is that do you think splitting the Post and PostRates model is better than just adding likes and dislikes field in the Post model? What is the use of splitting them when it just increases the number of lines of code to save the rates data?
@codeenvironment
@codeenvironment 3 жыл бұрын
Thanks Siddiq for the question. First doubt: you could do that, but then you will need to send two request to your API to get the post first and then the rates next and that is not a good approach especially when you have thousands of post. Plus you need more coding and effort in the frontend. Second doubt: adding likes and dislikes fields in the Post model is not wrong. but, splitting creates a better data and code structure ,helps with debugging and testing and makes your system more flexible cause you can link rates model with other models e.g( blogs, comments, articles ...etc) and actually you end up reducing the number of lines in your code.
@SiddiqNx
@SiddiqNx 3 жыл бұрын
@@codeenvironment Thank you! Got it now. These design decisions come only with experience I guess.
@LakshmanKumar-qp9xn
@LakshmanKumar-qp9xn 3 жыл бұрын
Hi it's very nice. But how to create more than one , for one to one relationship ..
@LakshmanKumar-qp9xn
@LakshmanKumar-qp9xn 3 жыл бұрын
For example.. X class contains a, b, c, d, one to one relationship.. How to we have write create method in class based views... Please give me suggestion..
@codeenvironment
@codeenvironment 3 жыл бұрын
@@LakshmanKumar-qp9xn You can just create an object for each relational field ( a, b, ... c) like what I did at 10:40 and then add them to the main object.
Django Rest Framework API #22 / Many To Many Relationship , Nested Data
31:20
МАМА И STANDOFF 2 😳 !FAKE GUN! #shorts
00:34
INNA SERG
Рет қаралды 4,7 МЛН
🌊Насколько Глубокий Океан ? #shorts
00:42
Nutella bro sis family Challenge 😋
00:31
Mr. Clabik
Рет қаралды 11 МЛН
ОДИН ДЕНЬ ИЗ ДЕТСТВА❤️ #shorts
00:59
BATEK_OFFICIAL
Рет қаралды 9 МЛН
Django Rest Framework API #30 / Improve API Response Using Hyperlinks
28:38
Django REST framework: Concept behind different types of serializers?
55:40
Django Rest Framework API #21 / Building Custom User Model
42:57
Code Environment
Рет қаралды 15 М.
Understanding Django Model Relationships
25:56
Pretty Printed
Рет қаралды 94 М.
Django REST Framework Model Relationships
14:32
Pretty Printed
Рет қаралды 67 М.
Extending User model using One-To-One Relationship - Django
11:05
Django Rest Framework | Serializers & CRUD
22:40
Dennis Ivy
Рет қаралды 381 М.
Nested Serializer | DRF
13:54
Django World
Рет қаралды 2,7 М.
МАМА И STANDOFF 2 😳 !FAKE GUN! #shorts
00:34
INNA SERG
Рет қаралды 4,7 МЛН