Skip to content

Commit

Permalink
feat: professor link table to efficiently store links
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaspalma committed Sep 15, 2024
1 parent b49bf28 commit 9a5ac39
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions django/university/controllers/ClassController.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from university.models import Class, Professor, Slot, SlotProfessor
from university.models import Class, Professor, Slot, SlotProfessor, ProfessorLink


class ClassController:
Expand All @@ -9,11 +9,14 @@ def get_professors(slot):
professors = []

for slot_professor in slot_professors:
professor_link = ProfessorLink.objects.get(pk=slot_professor.link_id)

professor = Professor.objects.get(id=slot_professor['professor_id'])
professors.append({
'id': professor.id,
'acronym': professor.professor_acronym,
'name': professor.professor_name
'name': professor.professor_name,
'link': professor_link.link
})

return {
Expand Down
9 changes: 7 additions & 2 deletions postgres/sql/00_schema_postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ CREATE TABLE "public"."slot_class" (
"class_id" bigint NOT NULL
);

CREATE TABLE "public"."professor_link" (
id SERIAL PRIMARY KEY,
"link" varchar(256) NOT NULL
);

--
-- TOC entry 225 (class 1259 OID 16806)
Expand All @@ -173,7 +177,8 @@ CREATE TABLE "public"."slot_class" (

CREATE TABLE "public"."slot_professor" (
"slot_id" integer NOT NULL,
"professor_id" integer NOT NULL
"professor_id" integer NOT NULL,
"link_id" integer NOT NULL
);


Expand Down Expand Up @@ -317,7 +322,7 @@ ALTER TABLE ONLY "public"."slot"
--

ALTER TABLE ONLY "public"."slot_professor"
ADD CONSTRAINT "slot_professor_pkey" PRIMARY KEY ("slot_id", "professor_id");
ADD CONSTRAINT "slot_professor_pkey" PRIMARY KEY ("slot_id", "professor_id", "link_id");


--
Expand Down

0 comments on commit 9a5ac39

Please sign in to comment.