Source

openju / openju / model.py

Full commit
# -*- coding: utf-8 -*-

import datetime
from mongoengine import Document, ReferenceField, StringField, DateTimeField, ListField

class User(Document):
    jid = StringField(max_length=200, required=True, unique=True)
    nick = StringField(max_length=200, required=True, unique=True)

class Message(Document):
    user = ReferenceField(User, required=True)
    body = StringField(required=True)
    dt = DateTimeField(default=datetime.datetime.utcnow, required=True)
    tags = ListField(StringField(max_length=50))
    reply_to = ReferenceField('self')
    
    meta = {
        'ordering': ['-dt']
    }
    
    def get_replies(self):
        from openju.bl.message import get_replies
        return get_replies(self.id)
    
    def post_reply(self, user, reply_body):
        from openju.bl.message import post_reply
        return post_reply(self, user, reply_body)

    def is_reply(self):
        return bool(self.reply_to)