You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As you can see, the brand filter returns a flat list of all possible in the categorie 'eiwitten'. Is there a way to make the queryset in brand a variable which I can input from my view function? This way I can use the filter for every page. Resulting in a unique brand list depending on the categorie. My view function for the 'eiwitten' looks as follows:
def eiwit(request):
#print(request.GET.getlist('brand'))
# filter alleen eiwitproducten
eiwit_list = ['eiwitten']
eiwit_filter = Q()
for item in eiwit_list:
eiwit_filter = eiwit_filter | Q(categorie=item)
brand_list = request.GET.getlist('brand')
brand_filter = Q()
for b in brand_list:
brand_filter = brand_filter | Q(brand=b)
products = models.Product.objects.filter(eiwit_filter).filter(brand_filter)
product_amount = len(products)
# sorteer filter
# HERE I WOULD LIKE TO INPUT A VARIABLE (cat for instance) WHICH CONTAINS THE CATEGORIE BELONGING TO THE VIEW
filtered = SortFilter(
request.GET,
queryset=products
)
# paginator
paginator = Paginator(filtered.qs, 12)
page = request.GET.get('page')
try:
response = paginator.page(page)
except PageNotAnInteger:
response = paginator.page(1)
except EmptyPage:
response = paginator.page(paginator.num_pages)
product_front_end = {
'final_products': response,
'filter': filtered,
'count': product_amount,
}
return render(request, 'producten/eiwit.html', product_front_end)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a filter which can be used to filter the products on brand(s), which looks like this:
As you can see, the brand filter returns a flat list of all possible in the categorie 'eiwitten'. Is there a way to make the queryset in brand a variable which I can input from my view function? This way I can use the filter for every page. Resulting in a unique brand list depending on the categorie. My view function for the 'eiwitten' looks as follows:
The actual filter:
Beta Was this translation helpful? Give feedback.
All reactions