【发布时间】:2015-02-16 23:04:23
【问题描述】:
我正在尝试找出一种从我的数据库中获取一些分析计数的好方法,而无需执行大量查询并以某种方式完成一个
我现在拥有的是一个返回计数的函数
def get_counts(self):
return {
'item_one_counts' : self.items_one.count(),
'item_two_counts' : self.items_two.count(),
'item_three_count' : self.items_three.count(),
}
等等。
我知道我可以使用 SELECT as count1,2,3 FROM table X 的原始查询来做到这一点
有没有更多的 django-y 方式来做到这一点?
【问题讨论】:
-
你检查我的解决方案了吗?
标签: python mysql django optimization query-optimization