No Description

models.py 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 django_models_ext import BaseModelMixin, SexModelMixin
  6. from shortuuidfield import ShortUUIDField
  7. class ScreenAdminInfo(BaseModelMixin):
  8. ACTIVATED = 1
  9. DISABLED = 2
  10. DELETED = 3
  11. USER_STATUS_TUPLE = (
  12. (ACTIVATED, u'已激活'),
  13. (DISABLED, u'已禁用'),
  14. (DELETED, u'已删除'),
  15. )
  16. admin_id = ShortUUIDField(_(u'admin_id'), max_length=32, blank=True, null=True, help_text=u'大屏管理员唯一标识', db_index=True, unique=True)
  17. unionid = models.CharField(_(u'unionid'), max_length=32, blank=True, null=True, help_text=u'微信 Union ID', db_index=True)
  18. openid = models.CharField(_(u'openid'), max_length=32, blank=True, null=True, help_text=u'微信 Open ID', db_index=True)
  19. name = models.CharField(_(u'name'), max_length=8, blank=True, null=True, help_text=u'用户姓名')
  20. sex = models.IntegerField(_(u'sex'), choices=SexModelMixin.SEX_TUPLE, default=SexModelMixin.UNKNOWN, help_text=u'用户性别')
  21. nickname = models.CharField(_(u'nickname'), max_length=255, blank=True, null=True, help_text=u'用户昵称')
  22. avatar = models.CharField(_(u'avatar'), max_length=255, blank=True, null=True, help_text=u'用户头像')
  23. phone = models.CharField(_(u'phone'), max_length=11, blank=True, null=True, help_text=u'用户电话', db_index=True)
  24. country = models.CharField(_(u'country'), max_length=16, blank=True, null=True, help_text=u'用户国家')
  25. province = models.CharField(_(u'province'), max_length=16, blank=True, null=True, help_text=u'用户省份')
  26. city = models.CharField(_(u'city'), max_length=16, blank=True, null=True, help_text=u'用户城市')
  27. location = models.CharField(_(u'location'), max_length=255, blank=True, null=True, help_text=u'用户地址')
  28. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  29. brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
  30. user_status = models.IntegerField(_(u'user_status'), choices=USER_STATUS_TUPLE, default=ACTIVATED, help_text=u'管理员状态', db_index=True)
  31. class Meta:
  32. verbose_name = _(u'ScreenAdminInfo')
  33. verbose_name_plural = _(u'ScreenAdminInfo')
  34. unique_together = (
  35. ('brand_id', 'unionid', 'openid'),
  36. )
  37. def __unicode__(self):
  38. return '%d' % self.pk
  39. @property
  40. def final_avatar(self):
  41. return self.avatar and self.avatar.replace(settings.QINIU_FILE_URL_BEFORE, settings.QINIU_FILE_URL_AFTER).replace(settings.QINIU_FILE_URL_BEFORE2, settings.QINIU_FILE_URL_AFTER)
  42. @property
  43. def data(self):
  44. return {
  45. 'admin_id': self.admin_id,
  46. 'nickname': self.nickname,
  47. 'avatar': self.final_avatar,
  48. }