5ee242bb4b7ac7850496f745b36ba27994a15ccf
[zzz-spline-forum.git] / splinext / forum / model / __init__.py
1 from sqlalchemy import Column, ForeignKey
2 from sqlalchemy.orm import relation
3 from sqlalchemy.types import DateTime, Integer, Unicode
4
5 from spline.model.meta import TableBase
6
7 class Forum(TableBase):
8 __tablename__ = 'forums'
9 id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
10 name = Column(Unicode(133), nullable=False)
11
12 class Thread(TableBase):
13 __tablename__ = 'threads'
14 id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
15 forum_id = Column(Integer, ForeignKey('forums.id'), nullable=False)
16 subject = Column(Unicode(133), nullable=False)
17
18 class Post(TableBase):
19 __tablename__ = 'posts'
20 id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
21 thread_id = Column(Integer, ForeignKey('threads.id'), nullable=False)
22 posted_time = Column(DateTime, nullable=False)
23 content = Column(Unicode(5120), nullable=False)
24
25
26 # XXX sort by time, how?
27 Forum.threads = relation(Thread, order_by=Thread.id.desc(), backref='forum')
28
29 Thread.posts = relation(Post, order_by=Post.posted_time.desc(), backref='thread')