|
# -*- 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):
user_id = ShortUUIDField(_('user_id'), max_length=32, blank=True, null=True, help_text='用户唯一标识', db_index=True, unique=True)
# 微信相关
unionid = models.CharField(_('unionid'), max_length=32, blank=True, null=True, help_text='微信 Unionid', db_index=True, unique=True)
openid = models.CharField(_('openid'), max_length=32, blank=True, null=True, help_text='微信 Openid', db_index=True, unique=True)
# 基本信息
nickname = models.CharField(_('nickname'), max_length=255, blank=True, null=True, help_text='用户昵称')
sex = models.IntegerField(_('sex'), choices=SexModelMixin.SEX_TUPLE, default=SexModelMixin.UNKNOWN, help_text='用户性别')
avatar = models.CharField(_('avatar'), max_length=255, blank=True, null=True, help_text='用户头像')
phone = models.CharField(_('phone'), max_length=11, blank=True, null=True, help_text='用户电话', db_index=True)
country = models.CharField(_('country'), max_length=255, blank=True, null=True, help_text='用户国家')
province = models.CharField(_('province'), max_length=255, blank=True, null=True, help_text='用户省份')
city = models.CharField(_('city'), max_length=255, blank=True, null=True, help_text='用户城市')
# 收货信息
consignee_name = models.CharField(_('consignee_name'), max_length=255, blank=True, null=True, help_text='收货人姓名')
consignee_phone = models.CharField(_('consignee_phone'), max_length=255, blank=True, null=True, help_text='收货人电话')
consignee_province = models.CharField(_('consignee_province'), max_length=255, blank=True, null=True, help_text='收货人省份')
consignee_city = models.CharField(_('consignee_city'), max_length=255, blank=True, null=True, help_text='收货人城市')
consignee_county = models.CharField(_('consignee_county'), max_length=255, blank=True, null=True, help_text='收货人区')
consignee_address = models.CharField(_('consignee_address'), max_length=255, blank=True, null=True, help_text='收货人地址')
class Meta:
verbose_name = _('用户信息')
verbose_name_plural = _('用户信息')
def __unicode__(self):
return self.pk
@property
def data(self):
return {
'unionid': self.unionid,
'openid': self.openid,
'nickname': self.nickname,
'sex': self.sex,
'avatar': self.avatar,
'phone': self.phone,
'country': self.country,
'province': self.province,
'city': self.city,
'user_id': self.user_id,
'consignee_name': self.consignee_name,
'consignee_phone': self.consignee_phone,
'consignee_province': self.consignee_province,
'consignee_city': self.consignee_city,
'consignee_county': self.consignee_county,
'consignee_address': self.consignee_address,
}
@property
def userinfo(self):
return {
'nickname': self.nickname,
'avatar': self.avatar,
}
class AdministratorInfo(BaseModelMixin):
ADMINISTRATOR = 0
USER_TYPE_TUPLE = (
(ADMINISTRATOR, '管理员'),
)
ACTIVATED = 1
DISABLED = 2
DELETED = 3
USER_STATUS_TUPLE = (
(ACTIVATED, '已激活'),
(DISABLED, '已禁用'),
(DELETED, '已删除'),
)
admin_id = ShortUUIDField(_('admin_id'), max_length=32, blank=True, null=True, help_text='管理员唯一标识', db_index=True, unique=True)
admin_type = models.IntegerField(_('admin_type'), choices=USER_TYPE_TUPLE, default=ADMINISTRATOR, help_text='管理员类型', db_index=True)
name = models.CharField(_('name'), max_length=255, blank=True, null=True, help_text='管理员名称')
password = models.CharField(_('password'), max_length=255, blank=True, null=True, help_text='管理员密码')
encryption = models.CharField(_('encryption'), max_length=255, blank=True, null=True, help_text='管理员密码')
user_status = models.IntegerField(_('user_status'), choices=USER_STATUS_TUPLE, default=ACTIVATED, help_text='管理员状态', db_index=True)
class Meta:
verbose_name = _('管理员信息')
verbose_name_plural = _('管理员信息')
def __unicode__(self):
return '{}-{}'.format(self.name, self.phone)
|