from sqlalchemy import Column, Integer, Text, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Topic(Base):
__tablename__ = 'topic'
id = Column(Integer, primary_key=True)
num_posts = Column(Integer, )
num_views = Column(Integer, )
first_post = Column(Text, )
topic_title = Column(Text, )
topic_id = Column(Integer, index=True, )
post_date = Column(DateTime)
delete_date = Column(DateTime, nullable=True, )
forum_id = Column(Integer, ForeignKey('forum.id'))
member_id = Column(Integer, ForeignKey('member.id'))
def __init__(self, num_posts, num_views, first_post,
topic_title, topic_id, post_date, forum_id, member_id):
self.num_posts = num_posts
self.num_views = num_views
self.first_post = first_post
self.topic_title = topic_title
self.topic_id = topic_id
self.post_date = post_date
self.forum_id = forum_id
self.member_id = member_id
def __repr__(self):
return '<Topic %r>' % (self.topic_title)
class Member(Base):
__tablename__ = 'member'
id = Column(Integer, primary_key=True)
name = Column(Text, )
register_date = Column(DateTime)
deleted_date = Column(DateTime, nullable=True, )
topics = relationship('Topic', backref='member', lazy='dynamic', )
def __init__(self, name, register_date):
self.name = name
self.register_date = register_date
def __repr__(self):
return '<Member %r>' % (self.name)
class Forum(Base):
__tablename__ = 'forum'
id = Column(Integer, primary_key=True)
forum_id = Column(Integer)
name = Column(Text, )
topics = relationship('Topic', backref='forum', lazy='dynamic', )
def __init__(self, forum_id, name):
self.forum_id = forum_id
self.name = name
def __repr__(self):
return '<Forum %r>' % (self.name) |