Я использую django-eventtools и у меня вывод данных о происшествии в виде кортежа. Я попытался преобразовать это в список, чтобы иметь возможность циклически проходить через него, но я не могу заставить его работать. Моя переменная querytest - это моя попытка перебрать новый список из исходного кортежа.
Вот мой класс и метод, в котором я просто вызываю контекст для шаблона django:
class MyDashboardView(LoginRequiredMixin, TemplateView):
template_name = 'index2.html'
login_url = 'login/'
def get_context_data(self, **kwargs):
context = super(MyDashboardView, self).get_context_data(**kwargs)
context['events'] = self.get_events_items_context()
return context
def get_events_items_context(self):
context = {}
query = list(RecurringAudits.objects.all().all_occurrences())
querytest = [s for t in query for s in t]
context['query'] = querytest
return context
Вот мой код шаблона:
{% load static %}
{% block content %}
<div class="row">
{{ events.query }}
</div>
{% endblock %}
Метод all_occurrence выводит данные в формате генератора:
<generator object combine_occurrences at 0x7f07cee47258>
Вот как выглядит вывод переменной запроса:
[(datetime.datetime(2018, 3, 31, 0, 0, tzinfo=<UTC>), datetime.datetime(2018, 3, 31, 0, 0, tzinfo=<UTC>), {'title': 'Monthly Update Schedule'}), (datetime.datetime(2019, 3, 31, 0, 0, tzinfo=<UTC>), datetime.datetime(2019, 3, 31, 0, 0, tzinfo=<UTC>), {'title': 'Monthly Update Schedule'}), (datetime.datetime(2020, 3, 31, 0, 0, tzinfo=<UTC>), datetime.datetime(2020, 3, 31, 0, 0, tzinfo=<UTC>), {'title': 'Monthly Update Schedule'})]
Вот как выглядит результат запроса:
[datetime.datetime(2018, 3, 31, 0, 0, tzinfo=<UTC>), datetime.datetime(2018, 3, 31, 0, 0, tzinfo=<UTC>), {'title': 'Monthly Update Schedule'}, datetime.datetime(2019, 3, 31, 0, 0, tzinfo=<UTC>), datetime.datetime(2019, 3, 31, 0, 0, tzinfo=<UTC>), {'title': ' Monthly Update Schedule'}, datetime.datetime(2020, 3, 31, 0, 0, tzinfo=<UTC>), datetime.datetime(2020, 3, 31, 0, 0, tzinfo=<UTC>), {'title': 'Monthly Update Schedule'}]
Мой желаемый вывод (или что-то подобное):
2018-3-31, 2018-3-31, Monthly Update Schedule, 2019-3-31, 2019-3-31, Monthly Update Schedule, 2020-3-31, 2020-3-31, Monthly Update Schedule