0

I want to create a listview with various optional filters. My url should be look like this:

shop/category_6/?manufacturer_id=3

And it works well when I put this url just in to the browser form. But when i try to add this option to a template it gives me NoReverseMatch. My template:

{% for manufacturer in manufacturer_list %}
    <p><a href = "{% url 'shop:item_list' category_id=category.id manufacturer_id=manufacturer.0 %}">{{manufacturer.1}}</a></p>
{% endfor %}

It is my view:

class ItemListView(ListView):
    model = Item
    context_object_name = 'item_list'
    template_name = 'shop/item_list.html'

def get_queryset(self, **kwargs):
    full_item_list=Item.objects.all()
    queryset=full_item_list.filter(category__id=int(self.kwargs['category_id']))
    manufacturer_id = self.request.GET.get('manufacturer_id')
    if manufacturer_id:
        queryset=queryset.filter(manufacturer__id=int(manufacturer_id))
    return queryset

def get_context_data(self, **kwargs):
    context = super(ItemListView, self).get_context_data(**kwargs)
    context['category']=get_object_or_404(Category, pk=self.kwargs['category_id'])
    context['manufacturer_list'] = self.get_queryset(**kwargs).values_list('manufacturer__id', 'manufacturer__name').distinct().order_by('manufacturer__name')
    return context

What is my mistake?

1 Answer 1

2

You didn't configure GET params... May be shop/category_6/?manufacturer_id=3

<a href = "{% url 'shop:item_list' category_id=category.id %}?manufacturer_id={{ manufacturer.0 }}">{{manufacturer.1 }}</a>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.