在此功能中,我无法单独过滤类别。那么请告诉我该怎么做?这里我使用数组模型字段的类别和规格。从这个数组模型字段我无法使用查询
获取类别列set category_name=Product.objects.values_list('categories', flat=True).distinct()
并且该过滤器应该是不同的值。那么检索此类别值的查询是什么
models.py
class Product(models.Model):
name = models.CharField(max_length=255)
image = models.ImageField(upload_to = '',blank="True")
categories = models.ArrayModelField(
model_container=Categories,
model_form_class=CategoriesForm
)
specifications = models.ArrayModelField(
model_container=Specifications,
model_form_class=SpecificationsForm
)
description = models.TextField()
reviews = models.ArrayModelField(
model_container=Reviews,
model_form_class=ReviewsForm
)
drizzly = models.BooleanField()
complete = models.BooleanField()
def __str__(self):
return self.name
class Categories(models.Model):
name = models.CharField(max_length=255)
class Meta:
abstract = True
views.py
def index(request):
data = Product.objects.all()
category_name=Product.objects.values_list('categories', flat=True).distinct()
return render(request, 'db.html', data':data,'category_name':category_name})