使用Django 1.1,我如何使用ORM創建交叉表(數據透視表)SQL查詢?如何使用Django ORM創建一個交叉表SQL查詢?
更新: 這些模型和輸出要求:
class Store(models.Model):
name = models.CharField(max_length=255)
...
class Order(models.Model):
store = models.ForeignKey(Store, blank=True, null=True, related_name='orders')
description = models.CharField(_('Description'), max_length=255)
quantity = models.IntegerField(blank=True, null=True)
type_detail = models.CharField(_('Type Detail'), max_length=255)
slug = models.SlugField(blank=True)
cost = models.DecimalField(_("Cost"), max_digits=14, decimal_places=2)
modified = models.DateTimeField(_('modified'), auto_now=True)
目前該視圖顯示的數據,像這樣:
Store | Type Detail | Quantity
----------------------------------
Walmart | Floor polish | 2
Walmart | Tiles | 1
Walmart | Milk | 4
Another | Floor polish | 2
Another | Tiles | 1
Another | Milk | 4
我要轉動此觀看像這樣的數據:
對於一家商店我需要知道數量
Store | Floor polish | Tiles | Milk
------------------------------------------------
Walmart | 2 | 1 | 4
Another | 2 | 1 | 4
我希望能解釋我需要什麼。
您將不得不提供更多的細節。你有什麼樣的模型,你想達到什麼樣的結果? – 2009-12-07 10:08:10
我使用模型詳細信息更新 – 2009-12-07 10:28:24