标签:publish 括号 区别 连表 related 聚合 耗资源 nec ref
from django.db.models import Q
book_queryset = models.Book.objects.filter(Q(‘title‘=‘python入门‘)|Q(‘price‘=555.55))
print(book_queryset)
q = Q()
q.connector(‘or‘)
res1 = modles.Book.objects.all()
res2 = modles.Book.objects.values(‘title‘)
res3 = modles.book.objects.only(‘title‘)
for r in res1:
print(r.title)
res4 = modles.Book.objects.defer(‘tilte‘)
for r in res4:
print(r.title)
res5 = modles.Book.objects.select_related(‘publish‘)
for r in res5:
print(r.publish.name)
res6 = modles.Book.objects.prefetch_related(‘author‘)
for r inb res6:
print(r.author.name)
标签:publish 括号 区别 连表 related 聚合 耗资源 nec ref
原文地址:https://www.cnblogs.com/zj420255586/p/11747726.html