Update to new frontpage API, and keep frontpage optional.
[zzz-spline-forum.git] / splinext / forum / model / __init__.py
index 089a879..a137866 100644 (file)
@@ -1,3 +1,5 @@
+from datetime import datetime
+
 from sqlalchemy import and_, Column, ForeignKey, Index
 from sqlalchemy.orm import relation
 from sqlalchemy.types import DateTime, Integer, Unicode
@@ -39,7 +41,7 @@ class Post(TableBase):
     thread_id = Column(Integer, ForeignKey('threads.id'), nullable=False)
     position = Column(Integer, nullable=False)
     author_user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
-    posted_time = Column(DateTime, nullable=False, index=True)
+    posted_time = Column(DateTime, nullable=False, index=True, default=datetime.now)
     content = Column(Unicode(5120), nullable=False)
 
 Index('thread_position', Post.thread_id, Post.position, unique=True)
@@ -48,7 +50,7 @@ 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')
 
-Thread.posts = relation(Post, order_by=Post.posted_time.desc(), lazy='dynamic', backref='thread')
+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)