我想按国家及品牌筛选我的产品,为此,我已经创建了一个观点:为什么过滤器不工作?
class CategoryView(ListView):
template_name = '__index.html'
context_object_name = 'products'
paginate_by = 20
def get_queryset(self):
queryset = Product.objects.filter(category__slug=self.kwargs.get('slug')).order_by('-created')
request = self.request
# Filter By Brand and Country
if request.GET.get('country'):
print(request.GET.get('country'))
queryset.filter(brand__country__slug=request.GET.get('country'))
if request.GET.get('brand'):
print(request.GET.get('brand'))
queryset.filter(brand__slug=request.GET.get('brand'))
print(queryset[0].brand.slug)
print(queryset[0].brand.country.slug)
return queryset
但是当我通过查询字符串这样的产品是不是过滤:品牌= ASTRA-金&国家= chehiya和打印功能告诉我:
chehiya ASTRA-金 威尼托 italiya
正如你所看到的chehiya!= italiya和astra-gold!= veneto。 Bun为什么发生这种情况
这是耻辱)THX –