1

私は以下のモデルを持っています。

class Category(MPTTModel):
    name = models.CharField(max_length=100, null=False, blank=False)
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')

    def __unicode__(self):
        return self.name

class Product(models.Model):
    name = models.CharField(max_length=250, null=False, blank=False)
    category = models.ForeignKey('Category')
    price = models.DecimalField(decimal_places=2, max_digits=7)

    def __unicode__(self):
        return self.name

class ProductAttribute(models.Model):
    products = models.ManyToManyField('Product')
    category = models.ForeignKey('Category')
    property = models.CharField(max_length=250, null=False, blank=False)
    value = models.CharField(max_length=250, null=False, blank=False)

特定のカテゴリと特定の属性に基づいて製品を選択できる必要があります。

たとえば、製品「ブレンダー」がある場合、特定の属性 (ブランド = 黒 & デッカーなど) を持つ特定のカテゴリ内のすべてのブレンダーを選択したいと考えています。

4

0 に答える 0