From 2b1bdb073dee48aff10a34e31ac579fbfd88e331 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Fri, 17 Feb 2017 15:24:40 -0500 Subject: [PATCH] python models: Implement Supporter.supperter_type() with filters. --- python/supporters/models.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/supporters/models.py b/python/supporters/models.py index b9e6e36..cc9e21d 100644 --- a/python/supporters/models.py +++ b/python/supporters/models.py @@ -112,12 +112,12 @@ class Supporter: return expose_wrapper def _supporter_type(self, payments): - for payment in payments.reverse(): - if payment.program is not None: - break - else: + try: + program = payments.filter(program__isnull=False).reverse()[0].program + except IndexError: return None - return payment.program.rsplit(':', 1)[-1] + else: + return program.rsplit(':', 1)[-1] supporter_type = _expose(_supporter_type) def _calculate_lapse_date(self, last_payment_date, supporter_type):