I make a website on Django, Postgresql database
There are the following tables in the database:
Faculty
- Id
- Title
The Department
- Id
- Title
- Faculty
- Teacher
- Id
- Name
- The Department
- Book Editions
- Teacher
- Title
- Publisher
- The year of publishing
It is necessary to display this data on the page in a hierarchical form:
- Chemical faculty
- Department of Organic Chemistry
- Sadulaev A.B.
The book edition of this teacher
The book edition of this teacher - Bogomoev A.P.
The book edition of this teacher
The book edition of this teacher
- Sadulaev A.B.
- Department of Biomolecular Chemistry
- Boltukayev A.A.
The book edition of this teacher
The book edition of this teacher
... - Makhov B.V.
...
- Boltukayev A.A.
- Department of Organic Chemistry
- Faculty of Mechanics and Mathematics
- Department of Applied Mathematics
- Kolmogorov A.N.
...
- Kolmogorov A.N.
- Department of Applied Mathematics
What is the best way to do this?
I see while one option:
Get all the data in one sql query using inner-join
Faculty Department Teacher Edition
Chemical Biomolek. Boltukaev Edition
Chemical Biomolek. Boltukaev Edition
Chemical Biomolek. Makhov Edition
Math
Then process the result of this query in python and present it in a hierarchical form (a list of lists), making a bunch of cycles
regroup
template filter - if I understood you correctly, then this is what you need - Eduard Izmalkov