标签:tle price comment color span title cts code info
F查询:
from django.db.models import F # 查询阅读数大于评论数的,书名 ret = models.Book.objects.filter(read_num__gt=F("comment_num")) print(ret) print(ret.values("title"))
结果:
# 给全部书的价格加1 models.Book.objects.all().update(price=F("price")+1)
Q查询:
from django.db.models import Q # 查询名字为西游记或者价格等于102的书籍 |:或 &:且 ret = models.Book.objects.filter(Q(title="西游记") | Q(price=102)) print(ret)
结果:
# 查询名字不为西游记的书籍 ret = models.Book.objects.filter(~Q(title="西游记")) print(ret)
结果:
标签:tle price comment color span title cts code info
原文地址:https://www.cnblogs.com/wangdianchao/p/12774241.html