So I have a model in Django that represents affiliates. The user receives a commission for each referral they get. How much the referrer receives depends on their user level. The user level depends on how many referrals they have. Under 5 referrals = Basic, under 10 referrals = Intermediate, under 15 referrals = Advanced.
How can I code the model so the user level is automatically determined by the amount of referrals an affiliate has? Lets say
class Affiliate(models.Model):
user= models.OneToOneField(User)
affiliate_id = models.PositiveIntegerField(primary_key=True)
referral_id = models.PositiveIntegerField(blank=False, null=False)
user_level = (
('B', 'Basic'),
('I', 'Intermediate'),
('A', 'Advanced'),
default='B')
referred_by = models.ForeignKey(referral_id, default=1)