'django-filter checkbox ajax
I am trying to implement django-filters + ajax(jquery)
after sending the request, the selected checkboxes "disappear"
I have little experience yet, tell me how to fix it? I need to connect django-filter + ajax(jquery)
```filters.py
class ItemFilter(django_filters.FilterSet):
category__name = django_filters.ModelMultipleChoiceFilter(field_name='name', widget=forms.CheckboxSelectMultiple,queryset=Category.objects.all())
class Meta:
model = Item
fields = ['category__name']
views.py
class CategoryList(View):
template_name = 'category/store.html'
def post(self, request):
select_check = self.request.POST.getlist('checkBOX[]')
categories = Category.objects.all().filter(id__in=select_check)
filter_test = ItemFilter(self.request.POST, queryset=categories)
.....
return render(request,template_name=self.template_name, context=context)
store.html
{% for c in filter_test.form %}
<form method="post" id="filter-checkbox" class="myform">
{% csrf_token %}
<div class="form-checkbox">
<p id="check_box_id" type="checkbox" name='check_box' >{{ c }}</p>
</div>
{% endfor %}
<button type="submit" class="myform-submit">Submit</button>
</form>
</div>```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|