Как создать таблицу с возможностью поиска из диктуемых данных?
Я хочу создать строку поиска для моего проекта Django, и пользователь сможет искать reporting_group
Я пытаюсь использовать django-filters для этого. Но я возвращаю dict и не могу использовать его с django-filters.
Есть ли способ сделать строку поиска для таблицы dict?
class ProcessTypeGroups(ReportsMixin, ListView):
'''Process per Type by Groups'''
model = User
active_tab = 'reports_group'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
fieldname = 'case_type_value'
date_1 = self.request.GET.get('date1')
date_2 = self.request.GET.get('date2')
cases = Case.objects.filter(date_created__range=[date_1, date_2]).values(fieldname).order_by(
fieldname).annotate(the_count=Count(fieldname))
process_types = ProcessType.objects.all()
report_group = {}
for i in cases:
for j in process_types:
if str(j) in i["case_type_value"]:
report_group[str(j.reporting_group)] = i["the_count"]
context['report_group'] = report_group
context['date_1'] = date_1
context['date_2'] = date_2
return context
Вывод report_group следующий: {'test': 27, 'Undefined': 44}
И мой шаблон таблицы:
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>Group</th>
<th>Number of Cases</th>
</tr>
</thead>
<tbody>
{% for index,key in report_group.items %}
<tr>
<td>
<a href="{% url 'process_groups' date_1 date_2 index %}" style="color: black">
{{ index }}
</a>
</td>
<td>{{ key }}</td>
</tr>
{% endfor %}
</tbody>
</table>