-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
62 lines (44 loc) · 1.5 KB
/
models.py
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
60
61
62
from typing import Optional
from sqlalchemy import (
Boolean,
Date,
ForeignKey,
Integer,
String,
)
from sqlalchemy.orm import (
DeclarativeBase,
Mapped,
mapped_column,
declarative_base,
relationship,
)
class Base(DeclarativeBase):
__allow_unmapped__ = True
class User(Base):
__tablename__ = "users"
username = mapped_column(String, primary_key=True)
phone = mapped_column(String, unique=True)
active = mapped_column(Boolean, default=True)
hash = mapped_column(String, unique=True)
pics: Mapped[Optional["Pic"]] = relationship("Pic", back_populates="uploader")
class Registration(Base):
__tablename__ = "registrations"
phone = mapped_column(String, primary_key=True)
username = mapped_column(String)
state = mapped_column(Integer)
class Prompt(Base):
__tablename__ = "prompts"
id = mapped_column(Integer, primary_key=True)
prompt = mapped_column(String, nullable=False)
date = mapped_column(Date, nullable=False)
pics: Mapped[Optional["Pic"]] = relationship("Pic", back_populates="parent")
class Pic(Base):
__tablename__ = "pics"
id = mapped_column(Integer, primary_key=True)
url = mapped_column(String)
prompt = mapped_column(Integer, ForeignKey("prompts.id"))
user = mapped_column(String, ForeignKey("users.username"))
winner = mapped_column(Boolean, default=False)
parent = relationship("Prompt", back_populates="pics")
uploader = relationship("User", back_populates="pics")