Show recent forum threads on the front page. Sucks, but.
[zzz-spline-forum.git] / splinext / forum / model / __init__.py
index 37beb61..64cfda5 100644 (file)
@@ -73,16 +73,18 @@ class Post(TableBase):
     position = Column(Integer, nullable=False)
     author_user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
     posted_time = Column(DateTime, nullable=False, index=True, default=datetime.now)
+    raw_content = Column(Unicode(5120), nullable=False)
     content = Column(Unicode(5120), nullable=False)
 
 Index('thread_position', Post.thread_id, Post.position, unique=True)
 
 
 # XXX sort by time, how?
-Forum.threads = relation(Thread, order_by=Thread.id.desc(), lazy='dynamic', backref='forum')
+Forum.threads = relation(Thread, lazy='dynamic', backref='forum')
 
 Thread.posts = relation(Post, order_by=Post.position.asc(), lazy='dynamic', backref='thread')
-Thread.first_post = relation(Post, primaryjoin=and_(Post.thread_id == Thread.id, Post.position == 1), uselist=False)
-Thread.last_post = relation(Post, primaryjoin=and_(Post.thread_id == Thread.id, Post.position == Thread.post_count), uselist=False)
+Thread.first_post = relation(Post, primaryjoin=and_(Post.thread_id == Thread.id, Post.position == 1), foreign_keys=[Post.thread_id], innerjoin=True, uselist=False, viewonly=True)
+# XXX THIS WILL NEED TO CHANGE when posts can be deleted!  Or change what 'position' means
+Thread.last_post = relation(Post, primaryjoin=and_(Post.thread_id == Thread.id, Post.position == Thread.post_count), foreign_keys=[Post.thread_id], innerjoin=True, uselist=False, viewonly=True)
 
-Post.author = relation(users_model.User, backref='posts')
+Post.author = relation(users_model.User, backref='posts', innerjoin=True)