How can I implement polling the table and keep the filter applied to it? [Django-filter] [HTMX]
I need to filter my database while live updating it too. However, the current rendering doubles the form and resets the filter to show all the data. How can I filter my data and update it at the same time
filter my data and update it at the same time
filters.py
import django_filters
from django_filters import DateFilter
from .models import CheckingStatus, Participant
from django.db.models import Q
class ParticipantFilter(django_filters.FilterSet):
class Meta:
model = Participant
fields = '__all__'
views.py
def display_view(request):
myFilter = ParticipantFilter(request.GET, queryset=Participant.objects.all())
data = myFilter.qs
return render(request, 'display.html', {'data': data, 'myFilter': myFilter})
HTML
<body>
<form method ="get">
{{myFilter.form}}
<button class "btn btn-primary" type = "Submit"></button>
</form>
<br><br>
<div id="table-results" hx-get="/display" hx-trigger="every 2s">
<table border="1" class="table table-dark table-hover">
<thead>
<th>First_name</th>
<th>Last_name</th>
<th>Age</th>
<th>Checking Status</th>
<th>Time</th>
<th>Date</th>
</thead>
{% for k in data %}
<tr>
<td>{{k.first_name}}</td>
<td>{{k.last_name}}</td>
<td>{{k.age}}</td>
<td>{{k.checking.checking_status}}</td>
<td>{{k.checking.time}}</td>
<td>{{k.checking.date}}</td>
</tr>
{% endfor %}
</table>
</div>
</body>
Thanks for your time