1 from sqlalchemy
import Column
, ForeignKey
2 from sqlalchemy
.orm
import relation
3 from sqlalchemy
.types
import DateTime
, Integer
, Unicode
5 from spline
.model
.meta
import TableBase
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)
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)
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)
26 # XXX sort by time, how?
27 Forum
.threads
= relation(Thread
, order_by
=Thread
.id.desc(), backref
='forum')
29 Thread
.posts
= relation(Post
, order_by
=Post
.posted_time
.desc(), backref
='thread')