fundgoal: Add provider convenience methods to FundraisingGoal.
This commit is contained in:
parent
2461bc19b1
commit
4fd27245d6
1 changed files with 14 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import random
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
class FundraisingGoal(models.Model):
|
class FundraisingGoal(models.Model):
|
||||||
|
@ -18,6 +20,18 @@ class FundraisingGoal(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('fundraiser_code_name',)
|
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):
|
class GoalProvider(models.Model):
|
||||||
fundraising_goal = models.ForeignKey(
|
fundraising_goal = models.ForeignKey(
|
||||||
|
|
Loading…
Reference in a new issue