fundgoal: Add provider convenience methods to FundraisingGoal.

This commit is contained in:
Brett Smith 2018-11-18 14:32:07 -05:00
parent 2461bc19b1
commit 4fd27245d6

View file

@ -1,3 +1,5 @@
import random
from django.db import models
class FundraisingGoal(models.Model):
@ -18,6 +20,18 @@ class FundraisingGoal(models.Model):
class Meta:
ordering = ('fundraiser_code_name',)
def providers(self):
return GoalProvider.objects.filter(fundraising_goal=self)
def random_providers(self, k=None):
providers = self.providers()
if not providers.exists():
return None
elif k is None:
return random.choice(providers)
else:
return random.sample(providers, k)
class GoalProvider(models.Model):
fundraising_goal = models.ForeignKey(