-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodels.py
41 lines (31 loc) · 1.25 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Model definitions for affiliate tracking"""
from django.conf import settings
from django.db import models
from mitxpro.models import TimestampedModel
class Affiliate(TimestampedModel):
"""Model that represents an affiliate"""
code = models.CharField(max_length=20, db_index=True, unique=True)
name = models.CharField(max_length=50, unique=True)
def __str__(self):
return f"Affiliate: id={self.id}, code={self.code}, name={self.name}"
class AffiliateReferralAction(TimestampedModel):
"""Model that represents some action that was taken by a user"""
affiliate = models.ForeignKey(
Affiliate, on_delete=models.CASCADE, related_name="affiliate_referral_actions"
)
created_user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name="affiliate_user_actions",
null=True,
blank=True,
)
created_order = models.ForeignKey(
"ecommerce.Order",
on_delete=models.CASCADE,
related_name="affiliate_order_actions",
null=True,
blank=True,
)
def __str__(self):
return f"AffiliateReferralAction: code={self.affiliate.code}, created_user_id={self.created_user_id}, created_order_id={self.created_order_id}"