您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

ORM创建数据库表的方式一

bubuko 2022/1/25 20:09:11 其他 字数 1239 阅读 864 来源 http://www.bubuko.com/infolist-5-1.html

from django.shortcuts import renderfrom app01 import models# Create your views here.#添加对象# create方式一def data_opr(req): pub=models.Publish.objects.filt ...
from django.shortcuts import render
from 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])



ORM创建数据库表的方式一

原文:https://www.cnblogs.com/startl/p/12387266.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶