django-filter - 仅显示相关的过滤器值

时间:2017-09-26 01:12:51

标签: python django django-filters

我正在使用django-filters,并且无法弄清楚如何只显示与我的查询集过滤器值相关的内容。

从下面的代码我按特定类别显示产品,但我收到的所有过滤器值可能不适用于该类别。如何仅显示相关的过滤器值?

models.py

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://example.com/$1 [R,L]


<IfModule mod_rewrite.c>
 RewriteCond %{REQUEST_URI} /+[^\.]+$
 RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
</IfModule>

views.py

Class Product(models.Model):
    name = models.CharField(max_length=512, unique=True, db_index=True)
    slug = models.SlugField(max_length=512, unique=True, db_index=True)
    categories = models.ManyToManyField(Category, related_name='products')
    description = models.TextField()
    status = models.BooleanField(default=True)
    manufacturer = models.CharField(max_length=64)
    common_attributes = JSONField(blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateField(auto_now=True)

Class ProductFilter(django_filters.FilterSet):
    manufacturer = django_filters.AllValuesMultipleFilter(name='manufacturer', widget=forms.CheckboxSelectMultiple)

Class Meta:
    model = Product
    fields = ['manufacturer']

0 个答案:

没有答案