4
這是一個相關的經理,我寫道:Django的 - queryset的額外方法返回空,計數()說,否則
class PortfolioItemManager(models.Manager):
use_for_related_fields = True
def extended(self):
return self.extra(select = {'current_price':'current_price', 'current_value':'current_price*quantity', 'gain':'current_price*quantity - cost'},
tables = ['pm_core_contract', ],
where = ['pm_core_contract.id = pm_core_portfolioitem.contract_id', ]
)
下面是樹樁我的結果:
In [10]: PortfolioItem.objects.extended()
Out[10]: []
In [11]: PortfolioItem.objects.extended().count()
Out[11]: 402
從計數結果() 是正確的。我在這裏錯過了什麼?
編輯:生成的SQL是正確的,可以直接對db執行。
EDIT2:該問題源自最後2個選擇參數,其特徵是算術運算。
請給我們您的PortfolioItem結構 – 2009-11-01 09:47:13