Source

openju / openju / model.py

# -*- coding: utf-8 -*-

import datetime
# from pymongo.objectid import ObjectId
# from mongokit import *
from mongoengine import *

# from openju.globals import g

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']
    }
    
# @con.register
# class User(Document):
#     __collection__ = 'user'
#     __database__ = 'openju'
#     structure = {
#         'jid': unicode,
#         'nick': unicode,
#         }
#     required_fields = ['jid', 'nick']
#     use_autorefs = True
#     indexes = [
#         {
#             'fields': ['nick', 'jid'],
#             'unique': True,
#             }
#         ]

# @con.register
# class Message(Document):
#     __collection__ = 'message'
#     __database__ = 'openju'
#     structure = {
#         'user': User,
#         'body': unicode,
#         'dt': datetime.datetime,
#         'reply_to': None, # Message
#         }
#     required_fields = ['user', 'body', 'dt']
#     default_values = {'dt': datetime.datetime.utcnow}
#     use_autorefs = True