user.py
# -*- coding: utf-8 -*-
from peewee import *
from common.models import BaseModel
class User(BaseModel):
openid = CharField(verbose_name="用户唯一标识",index=True,unique=True)
nickname = CharField(max_length=20,verbose_name="昵称")
avatar = CharField(max_length=200,verbose_name="头像",null=True)
notices = IntegerField(verbose_name="订阅消息次数",default=0)
login_time = DateTimeField(verbose_name="登录时间")
common.py
# -*- coding: utf-8 -*-
from datetime import datetime
from .settings import settings
from peewee import *
db = MySQLDatabase(
settings['db']['name'],
host=settings['db']['host'],
port=settings['db']['port'],
user=settings['db']['user'],
password=settings['db']['pwd']
)
def make_table_name(model_class):
model_name = model_class.__name__
return settings['table_prefix'] + model_name.lower()
class BaseModel(Model):
create_time = DateTimeField(verbose_name="创建时间",default = datetime.now())
class Meta:
database = db
table_function = make_table_name