summaryrefslogtreecommitdiff
path: root/app/models.py
diff options
context:
space:
mode:
authorRasmus Luha <rasmus.luha@gmail.com>2022-02-06 13:41:11 +0200
committerRasmus Luha <rasmus.luha@gmail.com>2022-02-06 13:41:11 +0200
commit6a6afdbe72c626b01245c9372c9d10be79789bb0 (patch)
treecfdb5aea7538296bad0105c813fce4cd33c19ef5 /app/models.py
parent5e19a0569288de21365c61b0db78639880732dd0 (diff)
restrucurring the stucture of the folderstruture --> structure
Diffstat (limited to 'app/models.py')
-rw-r--r--app/models.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/models.py b/app/models.py
new file mode 100644
index 0000000..97d1e35
--- /dev/null
+++ b/app/models.py
@@ -0,0 +1,31 @@
+from sqlalchemy import Column, Integer, String, Boolean, ForeignKey
+from sqlalchemy.orm import relationship
+from sqlalchemy.sql.expression import 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", nullable=False)
+ created_at = Column(TIMESTAMP(timezone=True), nullable=False, server_default=text('now()') )
+
+ owner_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
+ owner = relationship("User") #Fetcib owner_id põhjal( see foreign key) vastava Posti teinud User callsi useri
+
+class User(Base):
+ __tablename__ = "users"
+
+ id = Column(Integer, primary_key=True, nullable=False)
+ email = Column(String, nullable=False, unique = True)
+ password = Column(String, nullable=False)
+ created_at = Column(TIMESTAMP(timezone=True), nullable=False, server_default=text('now()') )
+
+
+class Vote(Base):
+ __tablename__ = "votes"
+ user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), primary_key=True)
+ post_id = Column(Integer, ForeignKey("posts.id", ondelete="CASCADE"), primary_key=True)