拍爱

models.py 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # -*- coding: utf-8 -*-
  2. from django.conf import settings
  3. from django.db import models
  4. from django.utils.translation import ugettext_lazy as _
  5. from pai2.basemodels import CreateUpdateMixin
  6. from group.models import GroupPhotoInfo
  7. class UserMessageInfo(CreateUpdateMixin):
  8. SYSTEM = 'system'
  9. COMMENT = 'comment'
  10. THUMBUP = 'thumbup'
  11. MESSAGE_TYPE = (
  12. (SYSTEM, u'系统'),
  13. (COMMENT, u'评论'),
  14. (THUMBUP, u'点赞'),
  15. )
  16. MESSAGE_TYPE_INFO = [
  17. {
  18. 'msg_type': SYSTEM,
  19. 'msg_type_desc': u'系统',
  20. 'msg_avatar': settings.SYSTEM_MESSAGE_AVATAR
  21. }, {
  22. 'msg_type': COMMENT,
  23. 'msg_type_desc': u'评论',
  24. 'msg_avatar': settings.COMMENT_MESSAGE_AVATAR
  25. }, {
  26. 'msg_type': THUMBUP,
  27. 'msg_type_desc': u'点赞',
  28. 'msg_avatar': settings.THUMBUP_MESSAGE_AVATAR
  29. }
  30. ]
  31. from_uid = models.CharField(_(u'from_uid'), max_length=255, blank=True, null=True, help_text=u'发送消息用户唯一标识', db_index=True)
  32. from_nickname = models.CharField(_(u'from_nickname'), max_length=255, blank=True, null=True, help_text=u'发送消息用户昵称')
  33. from_avatar = models.CharField(_(u'from_avatar'), max_length=255, blank=True, null=True, help_text=u'发送消息用户头像')
  34. to_uid = models.CharField(_(u'to_uid'), max_length=255, blank=True, null=True, help_text=u'接收消息用户唯一标识', db_index=True)
  35. group_id = models.CharField(_(u'group_id'), max_length=255, blank=True, null=True, help_text=u'群组唯一标识')
  36. photo_id = models.CharField(_(u'photo_id'), max_length=255, blank=True, null=True, help_text=u'飞图唯一标识')
  37. msg_type = models.CharField(_(u'msg_type'), max_length=255, default='system', help_text=u'消息类型', db_index=True)
  38. msg_title = models.CharField(_(u'msg_title'), max_length=255, blank=True, null=True, help_text=u'消息标题')
  39. msg_content = models.TextField(_(u'msg_content'), blank=True, null=True, help_text=u'消息内容')
  40. read = models.BooleanField(_(u'read'), default=False, help_text=u'消息是否已读')
  41. class Meta:
  42. verbose_name = _('usermessageinfo')
  43. verbose_name_plural = _('usermessageinfo')
  44. def __unicode__(self):
  45. return unicode(self.pk)
  46. @property
  47. def msg_info(self):
  48. try:
  49. group_photo = GroupPhotoInfo.objects.get(pk=self.photo_id)
  50. except GroupPhotoInfo.DoesNotExist:
  51. group_photo = None
  52. return {
  53. 'pk': self.pk,
  54. 'from_uid': self.from_uid,
  55. 'from_nickname': self.from_nickname,
  56. 'from_avatar': self.from_avatar,
  57. 'group_id': self.group_id,
  58. 'photo_id': self.photo_id,
  59. 'photo_url': group_photo and group_photo.photo_url,
  60. 'photo_thumbnail_url': group_photo and group_photo.photo_thumbnail_url,
  61. 'msg_title': self.msg_title,
  62. 'msg_content': self.msg_content,
  63. 'read': self.read,
  64. 'created_at': self.created_at,
  65. }