Django Relationships | One to Many Relationship | Many to One Relationship | Foreign Key | Example

preview_player
Показать описание
In this video, I'm gonna be explaining about one to many relationship in Django and many to one relationship in Django. At first, we will show you pictorial whiteboard representation of what exactly is Django one to many relationship and Django many to one relationship. We will then make a practical example of creating two models and connecting or making a relationship between them using Django Model ForeignKey ( foreign key ) field. We will discuss about fetching related model data and also the inverse relationships. We will show you how to override the default reverse model manager from model_set to any name. We will show you how to access related model data using field lookups in django. This is the second video of Django relationships playlist where we will be discussing about many to one relationship in django, one to many relationship in django, many to one relationship in django, many to many relationship in django, foreign key in django and much more content.

Subscribe | Code Band

Other videos in Code Band:

:) You Can Find Me On:
Рекомендации по теме
Комментарии
Автор

I have been confused about this for a couple of months. This is the best explanation I have seen so far. Very clear and easy to follow. Thank you!

jingai
Автор

its been 4 year and your tutorial are still better and easy to understated then others new guys

ZEYRI
Автор

Literally the best tutorial for OneToMany and ManyToOne relationship tutorial on entire youtube! Thank you so much for this amazing tutorial (BTW I enabled color inversion so video was like you enabled dark mode lol)

rvft
Автор

Tq man! Your the man.. your explanation so clear. Get me to boost my startup project.

ismailhamzah
Автор

This guy is great, how come I just discovered this channel. Great video!

Steady_stepper
Автор

bro god blessed you always, just because of you i solved my error thanx

minutescoding
Автор

This video explains model relations very well. Great job

ratulr
Автор

Very awesome Job bro well explained and to the point love it keep it up

franciscrawford
Автор

Thanks bro for easy clear cut explaination.

codevalley
Автор

i loved it very much! such an extended explanation! thx

АруукеАтабекова-рб
Автор

Thanks for tutorial. Django is so powerfull. Excelent job!

ches_ter
Автор

Haven't came across anyone explaining relational database query this way.. related_name thing was new to me and it helped me a lot to understand the concepts.. will be looking for more from you regarding django

mdshabbirrr
Автор

best video I watched so far. But how to get list of all employees where each employee object contains a sub-object with department details?

AsadUllah-jhjg
Автор

Hi, do you have video explaining foreign key relations among tables of different databases or any hint on how to achieve that?

VijayKumar-dqph
Автор

Nice video thank you for sharing. Is it possible to get all Departments with all employees in one single query? So that departments could display its employees in an html accordion. I have not found how to do that yet. Thank you.

juanuliss
Автор

Hi, I have 4 models Employee-holds the basic info of employees, Records-holds the records of the Employee with a One to one relationship with the Employee using employee_id as primary key. Also Record models is related to TimeSchedule with emp_time_sched as key (many to one relationship if you look from records). Now, I need to refer to Record model to get the employee_id, and also to get emp_time_sched to get thru to TimeSched Model. And these info will go to DailyTimeRecord Model. The error I am getting is that employee_id is an instance of the Employee. I did not issue any query to Employee model since I can get employee_id from record. Why am I getting such error? Hope you understand what I am after and give me advise on what to do with the error I am getting.

Also I copied your code in my machine, and come across the same problem when I issue the:


Attribute error: 'Department' object has no attribute 'employee_set'

>>> Emp.objects.create(name='John Simpson', age=35,
File "<console>", line 1
SyntaxError: positional argument follows keyword argument

These are the errors I encountered with the above models of mine. Thanks.

marissavictorio
Автор

please for the source code link of this project sir its AWESOME

vonputtkamer
Автор

How would you query every Department with their corresponding (all) Emloyyes ?

admfotad
Автор

I have a small doubt this all queries are we writing inside views. Py file? I have wrote it but lot of error come to me. Plz give the suggestion

sivaramk
Автор

How could we make the employee be in more than one department? Please help!

SamOween