-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwordpress_orm.py
38 lines (31 loc) · 1.23 KB
/
wordpress_orm.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
"""Create the ORM for a database schema with tables for holding
the full text content of posts on a wordpress site. Learn more at
http://docs.sqlalchemy.org/en/latest/."""
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import Column, String, Text, Integer, ForeignKey, DateTime
Base = declarative_base()
class Author(Base):
__tablename__ = 'author'
id = Column(Integer, primary_key = True)
name = Column(String)
posts = relationship('Post', backref = 'author')
comments = relationship('Comment', backref = 'author')
class Post(Base):
__tablename__ = 'post'
id = Column(Integer, primary_key = True)
date_gmt = Column(DateTime)
link = Column(String)
title = Column(String)
author_id = Column(Integer, ForeignKey('author.id'))
content = Column(Text)
comments = relationship("Comment", backref = "post")
class Comment(Base):
__tablename__ = 'comment'
id = Column(Integer, primary_key = True)
post_id = Column(Integer, ForeignKey('post.id'))
parent = Column(Integer)
author_id = Column(Integer, ForeignKey('author.id'))
author_name = Column(String())
date_gmt = Column(DateTime)
content = Column(Text)