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…
select * from tb where id > 1 # 对应关系 models.tb.objects.filter(1id__gt=) models.tb.objects.filter(id=1) models.tb.objects.filter(id__lt=1) 创建类 a.先写类 from django.db import models # 生成的表名 app01_userinfo class UserI…
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列,自增,主键 # 用户名列,…
1.准备数据表: from django.db import models class City(models.Model): name=models.CharField(max_length=32) nid=models.AutoField(primary_key=True) class Author(models.Model): name=models.CharField(max_length=32) nid=models.AutoField(primary_key=True) city=m…