This repository was archived by the owner on May 30, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
59 lines (37 loc) · 1.8 KB
/
models.py
File metadata and controls
59 lines (37 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from sqlmodel import Field, Relationship, SQLModel
class Form(SQLModel, table=True):
uuid: str = Field(primary_key=True, unique=True, index=True)
name: str
questions: list["Question"] = Relationship(back_populates="form")
entries: list["Entry"] = Relationship(back_populates="form")
class Question(SQLModel, table=True):
id: int | None = Field(primary_key=True)
name: str
description: str | None
allows_multiple_answer: bool = Field(default=False)
form_id: str = Field(foreign_key="form.uuid")
form: Form = Relationship(back_populates="questions")
variants: list["Variant"] = Relationship(back_populates="question")
class Variant(SQLModel, table=True):
id: int | None = Field(primary_key=True)
name: str
question_id: int = Field(foreign_key="question.id")
question: Question = Relationship(back_populates="variants")
class Entry(SQLModel, table=True):
id: int | None = Field(primary_key=True)
form_id: str = Field(foreign_key="form.uuid")
form: Form = Relationship(back_populates="entries")
answers: list["Answer"] = Relationship(back_populates="entry")
class Answer(SQLModel, table=True):
id: int | None = Field(primary_key=True)
body: str | None
question_id: int = Field(foreign_key="question.id")
question: Question = Relationship()
entry_id: int = Field(foreign_key="entry.id")
entry: Entry = Relationship(back_populates="answers")
answer_variants: list["AnswerVariant"] = Relationship(back_populates="answer")
class AnswerVariant(SQLModel, table=True):
variant_id: int | None = Field(foreign_key="variant.id", primary_key=True)
variant: Variant = Relationship()
answer_id: int | None = Field(foreign_key="answer.id", primary_key=True)
answer: Answer = Relationship(back_populates="answer_variants")