From 245e946fc2272f9a118d52c0eaf8756e3f656079 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sat, 24 Dec 2022 14:04:54 -0500 Subject: [PATCH] Add `is_active` annotatation helper to membershipworks.Member --- membershipworks/models.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/membershipworks/models.py b/membershipworks/models.py index 6cd0403..ae4588d 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.db.models import Q class Flag(models.Model): @@ -134,6 +135,14 @@ class Member(models.Model): db_table = "members" ordering = ("first_name", "last_name") + @classmethod + def with_is_active(cls): + return cls.objects.annotate( + is_active=Q(flags__name="Account On Hold", flags__type="label") + | Q(flags__name="CMS Membership on hold", flags__type="level") + | Q(flags__name="Former Members", flags__type="folder") + ) + class MemberFlag(models.Model): member = models.ForeignKey(Member, on_delete=models.PROTECT, db_column="uid")