-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
37 lines (28 loc) · 1.32 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
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.sql.expression import null, text
from sqlalchemy.sql.sqltypes import TIMESTAMP
from database import Base
class Post(Base):
__tablename__ = "posts"
id = Column(Integer, primary_key=True, nullable=False)
title = Column(String, nullable=False)
content = Column(String, nullable=False)
published = Column(Boolean, server_default='TRUE', default=True)
created_at = Column(TIMESTAMP(timezone=True), server_default=text('now()'), nullable=False)
owner_id = Column(Integer, ForeignKey('users.id', ondelete='CASCADE'), nullable=False)
owner = relationship("User")
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, nullable=False)
email = Column(String, nullable=False)
password = Column(String, nullable=False)
created_at = Column(TIMESTAMP(timezone=True), server_default=text('now()'), nullable=False)
class Vote(Base):
__tablename__ = "votes"
user_id = Column(Integer, ForeignKey('users.id', ondelete='CASCADE'),
primary_key=True,
nullable=False)
post_id = Column(Integer, ForeignKey('posts.id', ondelete='CASCADE'),
primary_key=True,
nullable=False)