标签:git str man public tin mod choices 项目 migrate
models:
找到项目文件下的__init__.py,写入:
1 import pymysql 2 pymysql.install_as_MySQLdb()
设置settings.py,添加app名称:
models.py
1 class Publisher(models.Model): 2 name = models.CharField(max_length=30, verbose_name="名称") 3 address = models.CharField("地址", max_length=50) 4 city = models.CharField(‘城市‘,max_length=60) 5 state_province = models.CharField(max_length=30) 6 country = models.CharField(max_length=50) 7 website = models.URLField() 8 9 class Meta: 10 verbose_name = ‘出版商‘ 11 verbose_name_plural = verbose_name 12 13 def __str__(self): 14 return self.name 15 16 17 class Author(models.Model): 18 name = models.CharField(max_length=30) 19 def __str__(self): 20 return self.name 21 22 class AuthorDetail(models.Model): 23 sex = models.BooleanField(max_length=1, choices=((0, ‘男‘),(1, ‘女‘),)) 24 email = models.EmailField() 25 address = models.CharField(max_length=50) 26 birthday = models.DateField() 27 author = models.OneToOneField(Author) 28 29 class Book(models.Model): 30 title = models.CharField(max_length=100) 31 authors = models.ManyToManyField(Author) 32 publisher = models.ForeignKey(Publisher) 33 publication_date = models.DateField() 34 price=models.DecimalField(max_digits=5,decimal_places=2,default=10) 35 def __str__(self): 36 return self.title
进入终端:
1 python3 manage.py makemigrations 2 python3 manage.py migrate
标签:git str man public tin mod choices 项目 migrate
原文地址:http://www.cnblogs.com/yan1314/p/7497383.html