pythondjangopinaxreferrals

Django referral system with pinax-referrals?


I am trying to create referral system in my Django project. I found very interesting app (pinax-referrals) for this task and want to test it.

From documentation its not clear how correctly to use it and there is no example. As I understand we need make next steps:

1) Create Profile models with such code:

from django.contrib.auth.models import User
from django.dispatch import receiver
from account.signals import user_signed_up  # django-user-account app
from pinax.referrals.models import Referral

class Profile(models.Model):
    user = models.OneToOneField(User,on_delete=models.CASCADE)
    referral = models.OneToOneField(Referral, null=True, on_delete=models.CASCADE)

@receiver(user_signed_up)
def handle_user_signed_up(sender, user, form, **kwargs):
    Referral.create(redirect_to=user.profile.get_absolute_url())

2) Сreate custom signup view:

from account.views import SignupView
from pinax.referrals.models import Referral


class RegistrationView(SignupView):

    def after_signup(self, form):
        super(RegistrationView, self).after_signup(form)
        Referral.record_response(self.request, "USER_SIGNUP")

How correct are my steps? Could you give a simple example?


Solution

  • As I see this question is interesting for some people. For that's why I decided to share information. Several years ago I create a simple Django project which uses pinax-referrals package for the referral system. I hope this project could be helpful to someone.