-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathmodels.py
38 lines (28 loc) · 886 Bytes
/
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
#!/usr/bin/python3
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from database.configuration import Base
class Blog(Base):
"""
Blog class
Args:
Base (sqlalchemy.ext.declarative.api.Base): Base class
"""
__tablename__ = "blogs"
id = Column(Integer, primary_key=True, index=True)
title = Column(String)
body = Column(String)
user_id = Column(Integer, ForeignKey("users.id"))
creator = relationship("User", back_populates="blogs")
class User(Base):
"""
User class
Args:
Base (sqlalchemy.ext.declarative.api.Base): Base class
"""
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True)
name = Column(String)
email = Column(String)
password = Column(String)
blogs = relationship("Blog", back_populates="creator")