Changeset - 4fd27245d6e4
[Not reviewed]
0 1 0
Brett Smith (brett) - 3 years ago 2018-11-18 19:42:47
brett@sfconservancy.org
fundgoal: Add provider convenience methods to FundraisingGoal.
1 file changed with 14 insertions and 0 deletions:
0 comments (0 inline, 0 general)
www/conservancy/apps/fundgoal/models.py
Show inline comments
 
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(
0 comments (0 inline, 0 general)