2024-03-29 05:20:36 发布
网友
假设我有一个名为Best的模型
Best
我想知道,如果不需要查询所有内容,使用Best.objects.all()是更好的选择,还是{}总体性能更好
Best.objects.all()
使用Best.objects.all()然后使用Python测试if this == that不是一个好主意。Best.objects.filter(this = that)当数据库执行检查时,性能会更好。只有满足检查条件的对象才会在Python中可用。在
if this == that
Best.objects.filter(this = that)
让我们再举一个例子:amount = len(Best.objects.all())要比amount = Best.objects.all().count()慢得多,因为Python不需要解决这个问题。在
amount = len(Best.objects.all())
amount = Best.objects.all().count()
使用
Best.objects.all()
然后使用Python测试if this == that
不是一个好主意。Best.objects.filter(this = that)
当数据库执行检查时,性能会更好。只有满足检查条件的对象才会在Python中可用。在让我们再举一个例子:
amount = len(Best.objects.all())
要比amount = Best.objects.all().count()
慢得多,因为Python不需要解决这个问题。在相关问题 更多 >
编程相关推荐