Nenhuma Descrição

models.py 2.2KB

    # -*- 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(_(u'nickname'), 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'用户性别') 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'用户城市') 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 } @property def userinfo(self): return { 'nickname': self.nickname, 'avatar': self.avatar, }