我正在Django中构建电子商务应用程序。所以我遇到了一个设计障碍,在没有产品的情况下我无法实现针对产品的类别专用过滤器 在产品模型中添加不必要的属性。
class Product(models.Model):
image = models.ImageField(upload_to='product_images/')
title = models.CharField(max_length=255)
pub_date = models.DateTimeField(default=now())
subline = models.CharField(max_length=255)
product_price = models.IntegerField()
color = models.ForeignKey('Colors', on_delete=models.CASCADE, blank=True, null=True, to_field="name")
size = models.CharField(max_length=255)
details = models.TextField()
category = models.ForeignKey('marketplace.MarketCategory', on_delete=models.CASCADE, blank=True, null=True)
sub_category = models.ForeignKey('marketplace.MarketSubCategory', on_delete=models.CASCADE, blank=True)
owner = models.ForeignKey(Vendor, on_delete=models.PROTECT)
def __str__(self):
return self.title