Answer the question
In order to leave comments, you need to log in
How to build a table for building a database of relatives?
Good afternoon Guru!
Please tell me how to correctly build a table (maybe more than one) and identify the rows of the table so that you can build simple queries.
Well, let's say there is a user: Ivanov Ivan Anatolyevich, he can be a son and a father at the same time! So he has a father - Ivanov Anatoly Maksimovich and has a son - Ivanov Matvey Ivanovich. Accordingly, the user Ivanov Anatoly Maksimovich has a son - Ivanov Ivan Anatolyevich and a grandson - Ivanov Matvey Ivanovich. There is only one reinforced concrete rule - a father always has one son.
So I have a dilemma - how to build a table and how to order indexes denoting fathers, grandfathers and grandchildren of the same lineage, so that later I can easily and quickly build queries of this kind: Display all grandchildren of the main users or display all those who are the current father? Or display the great-grandfathers of current users?
Answer the question
In order to leave comments, you need to log in
There is only one reinforced concrete rule - a father always has one son.
Vlob decision
Human:
ancestor_female = ForeignKey(Human)
ancestor_male = ForeignKey(Human)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question