models.类.objects.create(**{"name":"武沛齐","age":19})
obj = models.类(name="武沛齐",age=19)
obj.save()
obj_list = [
models.类(name="武沛齐",age=19),
models.类(name="武沛齐",age=19),
models.类(name="武沛齐",age=19),
models.类(name="武沛齐",age=19),
models.类(name="武沛齐",age=19)
。。。
]
models.类.objects.bulk_create(obj_list,batch_size=10)
⚠️注意如果是外键的话要放的是对象
name_object = UserInfo.objects.get(name=request.POST["name"]) #获取当前外键的名字->对象
Integral.objects.create(user_name=name_object)#写入Mysql 外键必须是对象
queyrset = models.类.objects.filter(name="武沛齐",age=19) # [obj,obj,]
queyrset = models.类.objects.filter(**{"name":"武沛齐","age":19}) # []
obj = models.类.objects.filter(name="武沛齐",age=19).first() # obj / None
queyrset = models.类.objects.filter(age=19)
queyrset = models.类.objects.filter(age__gt=19)
queyrset = models.类.objects.filter(age__gte=19)
queyrset = models.类.objects.filter(age__lt=19)
queyrset = models.类.objects.filter(age__lte=19)
queyrset = models.类.objects.filter(age__gt=19, name="武沛齐")
queyrset = models.类.objects.filter(name__contains="中国")
queyrset = models.类.objects.exclude(id=9) # id !=9
queyrset = models.类.objects.filter(age=19).order_by("id")
queyrset = models.类.objects.filter(age=19).order_by("-id")
queyrset = models.类.objects.filter(age=19).order_by("-id","name")
queyrset = models.类.objects.filter(age=19)[0:10]
# 更新
queyrset = models.类.objects.filter(id=2).update(age=19,name="武沛齐")
queyrset = models.类.objects.filter(id=2).update(**{"name":"武沛齐","age":19})
obj = models.类.objects.filter(id=2).first()
obj.name = "武沛齐"
obj.age = 19
obj.save()
# 删除
models.类.objects.filter(id=2).delete()