After creating the project, you can create an application;
Execute python manage.py startapp myApp \ \ System32 under Windows \ cmd.exe: in the project directory C
After creating the application, you can see more than a directory under the project myApp
admin.py: Site Configuration
apps.py:
models.py: Model Configuration
test.py:
views.py: View
__init__.py: This is a tell python python package
After creating the application, you can activate the application:
Need to activate the application file Study settings.py file in the project directory folder in the configuration
After activating the application, you can configure the model;
To configure the model to design the structure of the database table:
We designed two tables, the first table:
tablename:Grades
Field Name:
gname
gdate
ggirlnum
gboynum
isDelete
tablename:Student
Field Name:
sname
sgender
sage
scontend
IsDelete
sgrade
After a good data structure design table, you can define the model:
Moudels.py defined under myApp in:
class Grades(models.Model): gname = models.CharField(max_length=20) gdate = models.DateField() ggirlnum = models.IntegerField() gboynum = models.IntegerField() isDelete = models.BooleanField(default=False) class Students(models.Model): sname = models.CharField(max_length=20) sgender = models.BooleanField(default=False) sage = models.IntegerField() scontend = models.CharField(max_length=20) isDelete = models.BooleanField(default=False) sgrade = models.ForeignKey('Grades') #关联外键
定义好模型之后,可以在数据库生成数据表:
1、迁移文件:python manage.py makemigrations