环境准备: 表结构 from django.db import models # Create your models here. class Publisher(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=) class Book(models.Model): id = models.AutoField(primary_key=True) name = mod
db_index=True 如果设置该字段就可以设置索引 auto_now_add 代表设置创建时候的时间 auto_now 每次更新数据记录时会更新该字段 to_field 设置要关联表的字段,一般是ID related_time 反向操作时,使用的字段名,用于代替原反向查询时的表名_set class Classes(models.Model): name = models.CharField(max_length=32) class Student(models.Model): n
model.py from django.db import models # Create your models here. class Book(models.Model): nid = models.AutoField(primary_key=True) title = models.CharField(max_length=64) publishDate = models.DateField() price = models.DecimalField(max_digits=5, dec