我想做一个按钮,过滤产品的类别
我添加了产品标签,因为我需要颜色、尺寸等。
如何从外键中的外键获取类别数据?在视图中.py
型号.py
class Categorie(models.Model):
naam = models.CharField(max_length=150,db_index=True)
#
#
class Product(models.Model):
slug = models.SlugField(unique=True, primary_key=True)
titel = models.CharField(max_length=200)
categorie = models.ForeignKey(Categorie, on_delete=models.CASCADE)
#
#
class ProductAtribuut(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE, blank=False)
price = models.FloatField(default=0)
image = models.ImageField(blank=True, upload_to='gerechten/')
visible = models.BooleanField(default=True)
#
#
我不能用这个来分类。
视图.py
product = productatribuut.filter(categorie=categorie))
return render(request, 'pages/index.html', {product})
如果有人知道,请给我一个例子,我可以怎么做。提前谢谢。真的很感激<三
1条答案
按热度按时间cwtwac6a1#
你可以这样做:
假设您将使用类别的id,