A
A
alexkomp2019-07-29 21:41:03
Django
alexkomp, 2019-07-29 21:41:03

How to filter goods by seller (seller is a user in a certain group)?

How to add a field to the filtering form where you can select a seller and only the goods of this seller will remain on the site?
filter form

class FilterWare(forms.Form):
    max_price = forms.DecimalField(max_digits = 7, decimal_places=0, required=False)  
    ...

views.py
def shop_ware(request):
    ware = Ware.objects.all()
    form = FilterWare(request.GET)
    if form.is_valid():
        if form.cleaned_data["max_price"]:
            ware = ware.filter(prise__gte=form.cleaned_data["max_price"])
    context ={
        'ware': ware,
        'form': form
    }
    return render(request, 'index.html', context)

and then I render the form into a template

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question