标签:price init set 小数 settings pytho __init__ ack rate
建数据库
models.py下
# Create your models here. class Book(models.Model): id = models.AutoField(primary_key=True) title = models.CharField(max_length=32) pub_date = models.DateField() price = models.DecimalField(max_digits=8,decimal_places=2) #最大8位(包含小数) 两位小数 publish = models.CharField(max_length=32)
配置settings
项目 __init__ 下:
import pymysql
pymysql.install_as_MySQLdb()
python manage.py makemigrations
python manage.py migrate
如果想打印orm转换的sql语句,settings下:
LOGGING = { ‘version‘: 1, ‘disable_existing_loggers‘: False, ‘handlers‘: { ‘console‘:{ ‘level‘:‘DEBUG‘, ‘class‘:‘logging.StreamHandler‘, }, }, ‘loggers‘: { ‘django.db.backends‘: { ‘handlers‘: [‘console‘], ‘propagate‘: True, ‘level‘:‘DEBUG‘, }, } }
标签:price init set 小数 settings pytho __init__ ack rate
原文地址:https://www.cnblogs.com/Jnhnsnow/p/11631732.html