No Description

models.py 2.6KB

    # -*- coding: utf-8 -*- from django.conf import settings from django.db import models from django.utils.translation import ugettext_lazy as _ from pai2.basemodels import CreateUpdateMixin class UserMessageInfo(CreateUpdateMixin): SYSTEM = 'system' COMMENT = 'comment' THUMBUP = 'thumbup' MESSAGE_TYPE = ( (SYSTEM, u'系统'), (COMMENT, u'评论'), (THUMBUP, u'点赞'), ) MESSAGE_TYPE_INFO = [ { 'msg_type': SYSTEM, 'msg_avatar': settings.SYSTEM_MESSAGE_AVATAR }, { 'msg_type': COMMENT, 'msg_avatar': settings.COMMENT_MESSAGE_AVATAR }, { 'msg_type': THUMBUP, 'msg_avatar': settings.THUMBUP_MESSAGE_AVATAR } ] from_uid = models.CharField(_(u'from_uid'), max_length=255, blank=True, null=True, help_text=u'发送消息用户唯一标识', db_index=True) from_nickname = models.CharField(_(u'from_nickname'), max_length=255, blank=True, null=True, help_text=u'发送消息用户昵称') from_avatar = models.CharField(_(u'from_avatar'), max_length=255, blank=True, null=True, help_text=u'发送消息用户头像') to_uid = models.CharField(_(u'to_uid'), max_length=255, blank=True, null=True, help_text=u'接收消息用户唯一标识', db_index=True) group_id = models.CharField(_(u'group_id'), max_length=255, blank=True, null=True, help_text=u'群组唯一标识') photo_id = models.CharField(_(u'photo_id'), max_length=255, blank=True, null=True, help_text=u'飞图唯一标识') msg_type = models.CharField(_(u'msg_type'), max_length=255, default='system', help_text=u'消息类型', db_index=True) msg_title = models.CharField(_(u'msg_title'), max_length=255, blank=True, null=True, help_text=u'消息标题') msg_content = models.TextField(_(u'msg_content'), blank=True, null=True, help_text=u'消息内容') read = models.BooleanField(_(u'read'), default=False, help_text=u'消息是否已读') class Meta: verbose_name = _('usermessageinfo') verbose_name_plural = _('usermessageinfo') def __unicode__(self): return u'{0.title}'.format(self) @property def msg_info(self): return { 'pk': self.pk, 'from_uid': self.from_uid, 'from_nickname': self.from_nickname, 'from_avatar': self.from_avatar, 'group_id': self.group_id, 'photo_id': self.photo_id, 'msg_title': self.msg_title, 'msg_content': self.msg_content, 'read': self.read, 'created_at': self.created_at, }