ORM创建数据库表的方式一
from django.shortcuts import renderfrom app01 import models# Create your views here.#添加对象# create方式一def data_opr(req): pub=models.Publish.objects.filter(id=1) authors=models.Author.objects.filter(id_gt=1) #加models就对了 models.Book.objects.create( title=‘漂流记‘, price=1, color=‘red‘, publisher_id=4, ) book=models.Book.objects.filter(id=2).values(‘price‘)[{‘price‘:45}] authors=models.Author.objects.order_by(‘-id‘) authors=models.Author.objects.filter(id=1)[0] author1=models.Author.objects.get(id=3) author2=models.Author.objects.get(id=4) book = models.Book.objects.filter(id=3)[0] book.author.add(author1,author2) # 或者book.author.add(author1) # book.author.add(author2) #或者 book.author.add(*[author1,author2])
相关推荐
技术之博大精深 2020-10-16
jimgreatly 2020-08-03
Lingforme 2020-07-18
chenjiazhu 2020-07-08
Yort 2020-06-28
zry 2020-06-28
技术之博大精深 2020-06-10
Lingforme 2020-06-10
jediaellu 2020-06-02
PengQ 2020-06-01
jediaellu 2020-05-31
Danialzhou 2020-05-30
shawroad 2020-05-30
tlsmile 2020-05-28
jediaellu 2020-05-28