From aaaefd374c730343e81cb1a1fd5d9003d2f8168d Mon Sep 17 00:00:00 2001 From: Ester Date: Mon, 9 Oct 2023 17:23:57 +0200 Subject: [PATCH] Added filter for expired and upcoming events --- app/content/filters/registration.py | 9 ++++++++- app/content/models/registration.py | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/content/filters/registration.py b/app/content/filters/registration.py index 94f35b037..d12aca871 100644 --- a/app/content/filters/registration.py +++ b/app/content/filters/registration.py @@ -1,9 +1,16 @@ from django_filters.rest_framework import FilterSet - +from django_filters import filters from app.content.models.registration import Registration class RegistrationFilter(FilterSet): + event_has_ended = filters.BooleanFilter(method="filter_event_has_ended") + class Meta: model = Registration fields = ["has_attended", "is_on_wait"] + + def filter_event_has_ended(self, queryset, name, value): + return queryset.filter( + event_has_ended=value + ) \ No newline at end of file diff --git a/app/content/models/registration.py b/app/content/models/registration.py index 0f3a249fb..375bdf6ca 100644 --- a/app/content/models/registration.py +++ b/app/content/models/registration.py @@ -275,6 +275,10 @@ def check_registration_has_started(self): def check_registration_has_ended(self): if self.event.end_registration_at < now(): raise ValidationError("Påmeldingsfristen har passert") + + @property + def event_has_ended(self): + return self.event.event_has_ended def get_submissions(self, type=None): from app.forms.models import EventForm, Submission