From cbe8d24fe40e173471966ef8d2327a8db058d91d Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 19 Jan 2024 15:22:05 -0500 Subject: [PATCH] membershipworks: Add generated field to check if an event occured --- .../migrations/0008_event_occurred.py | 27 +++++++++++++++++++ membershipworks/models.py | 6 +++++ .../event_month_report.dj.html | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 membershipworks/migrations/0008_event_occurred.py diff --git a/membershipworks/migrations/0008_event_occurred.py b/membershipworks/migrations/0008_event_occurred.py new file mode 100644 index 0000000..30b1fc2 --- /dev/null +++ b/membershipworks/migrations/0008_event_occurred.py @@ -0,0 +1,27 @@ +# Generated by Django 5.0.1 on 2024-01-19 20:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("membershipworks", "0007_eventmeetingtime_duration"), + ] + + operations = [ + migrations.AddField( + model_name="event", + name="occurred", + field=models.GeneratedField( + db_persist=False, + expression=models.Q( + ("cap", 0), + ("count", 0), + ("calendar", 0), + _connector="OR", + _negated=True, + ), + output_field=models.BooleanField(), + ), + ), + ] diff --git a/membershipworks/models.py b/membershipworks/models.py index 1a65dda..92c3a96 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -10,6 +10,7 @@ from django.db.models import ( ExpressionWrapper, F, OuterRef, + Q, Subquery, Sum, ) @@ -384,6 +385,11 @@ class Event(BaseModel): category = models.ForeignKey(EventCategory, on_delete=models.PROTECT) calendar = models.IntegerField(choices=EventCalendar) venue = models.TextField(null=True, blank=True) + occurred = models.GeneratedField( + expression=~(Q(cap=0) | Q(count=0) | Q(calendar=EventCalendar.HIDDEN)), + output_field=models.BooleanField(), + db_persist=False, + ) # TODO: # "lgo": { # "l": "https://d1tif55lvfk8gc.cloudfront.net/656e3842ae3975908b05e304.jpg?1673405126", diff --git a/membershipworks/templates/membershipworks/event_month_report.dj.html b/membershipworks/templates/membershipworks/event_month_report.dj.html index 31abe76..ae4b61a 100644 --- a/membershipworks/templates/membershipworks/event_month_report.dj.html +++ b/membershipworks/templates/membershipworks/event_month_report.dj.html @@ -26,7 +26,7 @@ {% for event in object_list %} - + {{ event.title }}