From 07c741c785761cfa0e9895e35ba7e1f1549ce676 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Wed, 21 Oct 2020 16:39:17 +0100 Subject: started work on merging events sorted keyed on date for user profile page --- ctrack/users/views.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'ctrack/users') diff --git a/ctrack/users/views.py b/ctrack/users/views.py index 3ca574a..de3f4d1 100644 --- a/ctrack/users/views.py +++ b/ctrack/users/views.py @@ -1,3 +1,5 @@ +import itertools + from django.contrib import messages from django.contrib.auth import get_user_model from django.contrib.auth.mixins import LoginRequiredMixin @@ -5,7 +7,7 @@ from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from django.views.generic import DetailView, RedirectView, UpdateView -from ctrack.register.models import SingleDateTimeEvent +from ctrack.register.models import SingleDateTimeEvent, CAFSingleDateEvent, CAFTwinDateEvent User = get_user_model() @@ -24,8 +26,12 @@ class UserDetailView(DetailView): def get_context_data(self, **kwargs): context = super().get_context_data() user = self.request.user - single_date_events = SingleDateTimeEvent.objects.filter(user=user).all() - context["single_date_events"] = single_date_events + _single_date_events = SingleDateTimeEvent.objects.filter(user=user).all() + _caf_single_date_events = CAFSingleDateEvent.objects.all() + _caf_twin_date_events = CAFTwinDateEvent.objects.all() + _combined = list(itertools.chain(_caf_twin_date_events, _caf_single_date_events, _single_date_events)) + all_events = sorted(_combined, key=lambda x: x.date, reverse=True) + context["all_events"] = all_events return context -- cgit v1.2.3