0
我對使用Django ORM計數有疑問。Django + Oracle計數
項目:
class Item(models.Model):
member = models.ManyToManyField('self', through='Relationship', symmetrical=False, null=True, blank=True)
關係:
class Relationship(models.Model):
parent = models.ForeignKey(Item, related_name='p2c')
child = models.ForeignKey(Item, related_name='c2p')
TYPE_OF_RELATIONSHIP = (
('rel', 'Relation'),
('hier', 'Hierarchy'),
)
type = models.CharField(max_length=10, choices=TYPE_OF_RELATIONSHIP, null=False, blank=False)
類別:
class Category(Item):
def __str__(self):
return self.getName()
產品:
class Product(Item):
def __str__(self):
return self.getName()
我的產品通過「關係」模型與類別相關聯,如何獲得每個類別或每個類別的產品數量?
謝謝。