Extremely basic forum tables and browsing.
[zzz-spline-forum.git] / spline / plugins / forum / model / __init__.py
index f7d8a14..5ee242b 100644 (file)
@@ -1,7 +1,29 @@
 from sqlalchemy import Column, ForeignKey
 from sqlalchemy.orm import relation
-from sqlalchemy.types import Integer, Unicode
+from sqlalchemy.types import DateTime, Integer, Unicode
 
 from spline.model.meta import TableBase
 
-pass
+class Forum(TableBase):
+    __tablename__ = 'forums'
+    id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
+    name = Column(Unicode(133), nullable=False)
+
+class Thread(TableBase):
+    __tablename__ = 'threads'
+    id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
+    forum_id = Column(Integer, ForeignKey('forums.id'), nullable=False)
+    subject = Column(Unicode(133), nullable=False)
+
+class Post(TableBase):
+    __tablename__ = 'posts'
+    id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
+    thread_id = Column(Integer, ForeignKey('threads.id'), nullable=False)
+    posted_time = Column(DateTime, nullable=False)
+    content = Column(Unicode(5120), nullable=False)
+
+
+# XXX sort by time, how?
+Forum.threads = relation(Thread, order_by=Thread.id.desc(), backref='forum')
+
+Thread.posts = relation(Post, order_by=Post.posted_time.desc(), backref='thread')