码迷,mamicode.com
首页 > 其他好文 > 详细

django笔记

时间:2017-09-09 11:52:09      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:git   str   man   public   tin   mod   choices   项目   migrate   

models:

 找到项目文件下的__init__.py,写入:

技术分享

技术分享
1 import pymysql
2 pymysql.install_as_MySQLdb()
View Code

 

设置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
View Code

 

进入终端:

1 python3 manage.py makemigrations
2 python3 manage.py migrate

 

django笔记

标签:git   str   man   public   tin   mod   choices   项目   migrate   

原文地址:http://www.cnblogs.com/yan1314/p/7497383.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!