Я делаю фильтрацию. У меня есть первоначальные результаты на моей странице, затем есть форма, в которой при выборе я хочу отфильтровать некоторые данные и обновить шаблон.
Шаблон, похоже, не обновляется.
from .services import service
# Home Page View
def home_view(request, *args, **kwargs):
update_list = service.get_updates()
if request.method == 'POST':
filter_string = request.POST.get('filter')
update_list = [update for update in update_list if update['type'] == filter_string]
print(len(update_list))
page = request.GET.get('page', 1)
paginator = Paginator(update_list, 2)
try:
updates = paginator.page(page)
except PageNotAnInteger:
updates = paginator.page(1)
except EmptyPage:
updates = paginator.page(paginator.num_pages)
context = {
'updates': updates
}
return render(request, "home.html", context)
Файл шаблона:
<form method="post" id="filterformhome">
{% csrf_token %}
<select class="frm-input" onchange="homeFilter(this);">
<option value="job">{% trans "Jobs" %}</option>
<option value="market">{% trans "Products" %}</option>
<option value="question">{% trans "Questions" %}</option>
<option value="blog">{% trans "Blogs" %}</option>
</select>
</form>
{% for update in updates %}
{{update.title}}
{% endfor %}
Что может быть лучше для этого?