Django: Implementing a referral program

后端 未结 4 1645
深忆病人
深忆病人 2021-02-13 21:07

I have an ecommerce website that works in a classical way: people sign up, buy a product with their CC.

It uses the default Django auth system for users and registration

4条回答
  •  我在风中等你
    2021-02-13 21:20

    You could use a very simple model to keep track of them

    class UserReferral(models.Model):
        referrer = models.ForeignKey(User)
        referred = models.ForeignKey(User)
    
        class Meta:
            unique_together = (('referrer', 'referred'),)
    

    Then you can count how many a user has referred:

    UserReferral.objects.filter(referrer=user).count()
    

    Etc..

提交回复
热议问题