|
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django_models_ext import BaseModelMixin, SexModelMixin
from shortuuidfield import ShortUUIDField
class UserInfo(BaseModelMixin):
UNVERIFIED = 0
ACTIVATED = 1
DISABLED = 2
DELETED = 3
ASSIGN = 10
USER_STATUS = (
(UNVERIFIED, u'未验证'),
(ACTIVATED, u'已激活'),
(DISABLED, u'已禁用'),
(DELETED, u'已删除'),
(ASSIGN, u'已分配'),
)
MALE = 1
FEMALE = 0
SEX_TYPE = (
(MALE, u'男'),
(FEMALE, u'女'),
)
user_id = ShortUUIDField(_('user_id'), max_length=32, blank=True, null=True, help_text='用户唯一标识', db_index=True, unique=True)
# 微信授权用户
unionid = models.CharField(_(u'unionid'), max_length=32, blank=True, null=True, help_text=u'微信 Unionid', db_index=True, unique=True)
openid = models.CharField(_(u'openid'), max_length=32, blank=True, null=True, help_text=u'微信公众号 Openid', db_index=True, unique=True)
openid_miniapp = models.CharField(_(u'openid_miniapp'), max_length=32, blank=True, null=True, help_text=u'微信小程序 Openid', db_index=True, unique=True)
# 用户基本信息
name = models.CharField(_(u'name'), max_length=255, blank=True, null=True, help_text=u'用户姓名')
sex = models.IntegerField(_(u'sex'), choices=SexModelMixin.SEX_TUPLE, default=SexModelMixin.UNKNOWN, help_text=u'用户性别')
nickname = models.CharField(_(u'nickname'), max_length=255, blank=True, null=True, help_text=u'用户昵称')
avatar = models.CharField(_(u'avatar'), max_length=255, blank=True, null=True, help_text=u'用户头像')
phone = models.CharField(_(u'phone'), max_length=11, blank=True, null=True, help_text=u'用户电话', db_index=True)
country = models.CharField(_(u'country'), max_length=255, blank=True, null=True, help_text=u'用户国家')
province = models.CharField(_(u'province'), max_length=255, blank=True, null=True, help_text=u'用户省份')
city = models.CharField(_(u'city'), max_length=255, blank=True, null=True, help_text=u'用户城市')
user_status = models.IntegerField(_(u'user_status'), choices=USER_STATUS, default=UNVERIFIED, help_text=u'用户状态')
class Meta:
verbose_name = _(u'用户信息')
verbose_name_plural = _(u'用户信息')
def __unicode__(self):
return '%d' % self.pk
@property
def data(self):
return {
'user_id': self.user_id,
'unionid': self.unionid,
'openid': self.openid,
'openid_miniapp': self.openid_miniapp,
'name': self.name,
'sex': self.sex,
'nickname': self.nickname,
'avatar': self.avatar,
'phone': self.phone,
'country': self.country,
'province': self.province,
'city': self.city,
'user_status': self.user_status,
}
|