0
這是我的觀點的相關部分無法將關鍵字'可用'解析爲字段。選項包括:ID
def product_list(request, category_slug=None):
category = None
categories = Category.objects.all()
products = Product.objects.filter(available=True)
if category_slug:
category = get_object_or_404(Category, slug=category_slug)
products = products.filter(category=category)
return render(request,'list.html',{'category': category,
'categories': categories,'products': products})
這是我的模型的相關部分,我認爲這個問題是從這裏
class Product(models.Model):
category = models.ForeignKey(Category, related_name='products')
name = models.CharField(max_length=200, db_index=True)
slug = models.SlugField(max_length=200, db_index=True)
image = models.ImageField(upload_to='products/%Y/%m/%d', blank=True)
description = models.TextField(blank=True)
price = models.DecimalField(max_digits=10, decimal_places=2)
stock = models.PositiveIntegerField()
available = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
class Meta:
ordering = ('name',)
index_together = (('id', 'slug'),)
def __str__(self):
return self.name
下面是相關的部分我的回溯錯誤
FieldError at/
Cannot resolve keyword 'available' into field. Choices are: id
我們需要您獲取URL和完整回溯過的相關部分。 –