Commits

Konstantine Rybnikov committed 4f0327a

more on mongoengine

Comments (0)

Files changed (1)

openju/bl/message.py

 #         return val + 1
 
 def post_message(user, body):
-    message = Message()
-    message.user = user
-    message.body = body
+    message = (
+        Message(
+            user=user,
+            body=body))
     message.save()
     return message
     
 #             raise PostNotExistError(u'Message does not exist')
 #         return message
 
-def get_last_messages(limit=10):
-    return (
-        Message.objects
-        .find({'reply_to': {'$exists': False}})
-        .sort('dt', DESCENDING)
-        .limit(limit))
+def get_last_messages(skip=None, limit=10):
+    return Message.objects(reply_to__exists=False)[skip:limit]
     
     # with get_mongo_db() as db:
     #     messages = (