时间:2021-07-01 10:21:17 帮助过:18人阅读
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创建数据库表的方式一
标签:obj mod publish filter tle values mode book author