django的orm操作优化 models.py from django.db import models class Author(models.Model): name = models.CharField(max_length=16) age = models.IntegerField() class Book(models.Model): authors = models.ManyToManyField('Author') pubs = models.ForeignKey("Publis…
ORM操作 select * from tb where id > 1 # 对应关系 models.tb.objects.filter(id__gt=1) models.tb.objects.filter(id=1) models.tb.objects.filter(id__lt=1) 创建类 a. 先写类 from django.db import models # app01_userinfo class UserInfo(models.Model): # id列,自增,主键 # 用户名列,…
Django之ORM总结 表结构 from django.db import models # 一对多:班级与学生 # 多对多:班级与老师 # Create your models here. #创建班级表 class Classes(models.Model): title = models.CharField(max_length=32) n=models.ManyToManyField('Teachers',related_name="sssss") #创建老师表 class T…