|
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django_models_ext import BaseModelMixin, upload_file_path, upload_file_url, upload_path
from shortuuidfield import ShortUUIDField
class KOLInfo(BaseModelMixin):
kol_id = ShortUUIDField(_('kol_id'), max_length=32, blank=True, null=True, help_text='KOL 唯一标识', 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)
# 真实相关
name = models.CharField(_('name'), max_length=32, blank=True, null=True, help_text='KOL 姓名')
phone = models.CharField(_('phone'), max_length=11, blank=True, null=True, help_text='KOL 电话', db_index=True)
# 昵称相关
nickname = models.CharField(_('nickname'), max_length=32, blank=True, null=True, help_text='KOL 昵称')
avatar = models.ImageField(_('avatar'), upload_to=upload_path, blank=True, null=True, help_text='KOL 头像')
banner = models.ImageField(_('banner'), upload_to=upload_path, blank=True, null=True, help_text='KOL Banner图')
intro = models.TextField(_('intro'), blank=True, null=True, help_text='KOL 简介')
image = models.ImageField(_('image'), upload_to=upload_path, blank=True, null=True, help_text='KOL 简介图')
fans = models.IntegerField(_('fans'), default=0, help_text='KOL 粉丝数')
# 余额相关
fee = models.IntegerField(_('fee'), default=0, help_text='KOL 余额(分)')
total_fee = models.IntegerField(_('total_fee'), default=0, help_text='KOL 总收入(分)')
class Meta:
verbose_name = _('KOL 信息')
verbose_name_plural = _('KOL 信息')
def __unicode__(self):
return self.pk
@property
def final_nickname(self):
return self.nickname or self.name
@property
def avatar_path(self):
return upload_file_path(self.avatar)
@property
def avatar_url(self):
return upload_file_url(self.avatar)
@property
def banner_path(self):
return upload_file_path(self.banner)
@property
def banner_url(self):
return upload_file_url(self.banner)
@property
def image_path(self):
return upload_file_path(self.image)
@property
def image_url(self):
return upload_file_url(self.image)
@property
def data(self):
return {
'kol_id': self.kol_id,
'nickname': self.final_nickname,
'avatar_url': self.avatar_url,
'banner_url': self.banner_url,
'intro': self.intro,
'image_url': self.image_url,
'fans': self.fans,
}
|