Coverage for apps/rewards/models.py: 97%
28 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-09-27 13:55 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-09-27 13:55 -0600
1from django.db import models
3from base.models import RandomSlugModel, TimeStampedModel
6class Reward(RandomSlugModel, TimeStampedModel):
7 """
8 Model for Reward
9 """
11 organization = models.ForeignKey("organizations.Organization", on_delete=models.PROTECT, related_name="rewards")
13 name = models.CharField(max_length=256)
14 image = models.ForeignKey("organizations.OrganizationImage", on_delete=models.PROTECT, related_name="rewards")
15 description = models.TextField(blank=True, null=True)
17 value = models.DecimalField(max_digits=10, decimal_places=2)
18 points_required = models.PositiveSmallIntegerField()
19 total_number_of_claims = models.PositiveSmallIntegerField(null=True, blank=True)
20 total_number_of_claims_per_fan = models.PositiveSmallIntegerField(null=True, blank=True)
22 valid_from = models.DateField()
23 valid_to = models.DateField()
25 class Status(models.TextChoices):
26 DRAFT = "D", "Draft"
27 ACTIVE = "A", "Active"
28 INACTIVE = "I", "Inactive"
30 status = models.CharField(max_length=1, choices=Status.choices, default=Status.DRAFT)
32 class Meta:
33 ordering = ["name"]
35 def __str__(self):
36 return self.name
38 @property
39 def claimed_amount(self):
40 return self.claims.count()
43class RewardClaim(RandomSlugModel, TimeStampedModel):
44 """
45 Model for claimed Rewards from Fan
46 """
48 reward = models.ForeignKey("rewards.Reward", on_delete=models.PROTECT, related_name="claims")
49 fan = models.ForeignKey("users.Fan", on_delete=models.SET_NULL, related_name="rewards", null=True)
51 class Meta:
52 ordering = ["reward"]
54 def __str__(self):
55 return f"{self.reward}/{self.fan}"