标签:obj mod publish filter tle values mode book author
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])
标签:obj mod publish filter tle values mode book author
原文地址:https://www.cnblogs.com/startl/p/12387266.html