| 
              # -*- 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, '未验证'),
        (ACTIVATED, '已激活'),
        (DISABLED, '已禁用'),
        (DELETED, '已删除'),
        (ASSIGN, '已分配'),
    )
    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)
    openid_miniapp = models.CharField(_('openid_miniapp'), max_length=32, blank=True, null=True, help_text='微信小程序 Openid', db_index=True, unique=True)
    # 用户基本信息
    name = models.CharField(_('name'), max_length=255, blank=True, null=True, help_text='用户姓名')
    sex = models.IntegerField(_('sex'), choices=SexModelMixin.SEX_TUPLE, default=SexModelMixin.UNKNOWN, help_text='用户性别')
    nickname = models.CharField(_('nickname'), max_length=255, blank=True, null=True, 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='用户城市')
    user_status = models.IntegerField(_('user_status'), choices=USER_STATUS, default=UNVERIFIED, help_text='用户状态')
    class Meta:
        verbose_name = _('用户信息')
        verbose_name_plural = _('用户信息')
    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,
        }
class AdministratorInfo(BaseModelMixin):
    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)
    phone = models.CharField(_('phone'), max_length=11, blank=True, null=True, help_text='管理员电话', db_index=True)
    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='管理员密码')
    name = models.CharField(_('name'), max_length=255, blank=True, null=True, help_text='管理员姓名')
    point_id = models.CharField(_('point_id'), max_length=32, blank=True, null=True, help_text='隔离点唯一标识', db_index=True)
    point_name = models.CharField(_('point_name'), 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)
    @property
    def data(self):
        return {
            'admin_id': self.admin_id,
            'name': self.name,
            'point_id': self.point_id,
            'point_name': self.point_name,
        }
 
  |