Answer the question
In order to leave comments, you need to log in
Filtering a model by a limited but dynamic number of parameters in a get request?
Tell the Django view logic to filter the model by several possible parameters from the get request. Type the client can filter only on one field, and can on all. It can be by date period and at the same time select only the beginning / from and not select by, with the same price. I can't figure out how to keep track of all this.
Answer the question
In order to leave comments, you need to log in
If it is very rough, then something like this:
# ... Где-то здесь определяем quryset как нефильтрованный набор
title = request.GET.get('title')
price_min = request.GET.get('price_min')
price_max = request.GET.get('price_max')
if title:
quryset = quryset.filter(title=title)
if price_min and price_max:
quryset = quryset.filter(price__range=(price_min, price_max))
elif price_min:
quryset = quryset.filter(price__gte=price_min)
elif price_max:
quryset = quryset.filter(price__lt=price_max)
quryset =
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question