3

I want to create a two-sided benefit referral system, with different types of referrals in django using the anafero app.

I looked at this article and looked at the documentation for anafero and I cannot make sense of it. Can someone please give an simple example of:

  1. What database changes need to be made, i.e. which models need to be created and how the user object needs to be changed
  2. Which view needs to be created
  3. How to display the referral url in the template
Cheng
  • 770
  • 11
  • 22

1 Answers1

0

Anafero is outdated. Instead of it you can use pinax_referrals

  1. Install the package as it described in documentation, add middleware etc, synchronize database.
  2. Depending on what do you use for signing up hack the view. In my case I have reimplemented SignUp view and added following lines inside:

    profile = user.userprofile
    referral = Referral.create(
        user= user,
        redirect_to= "/"
    )
    profile.ref = referral
    profile.save()
    
  3. You see that when User signs up the Refferal object is created and saved into User profile. It means that you have to change the model for UserProfile and add additional field:

Import:

from pinax.referrals.models import Referral

Inside model:

ref = models.OneToOneField(
    Referral,
    null=True,
    on_delete=models.CASCADE,
)
  1. Make migrations, migrate, check in the admin if new fields are added, try to sign up and see whether the new Referral object is created and saved.
Alexander Tyapkov
  • 4,837
  • 5
  • 39
  • 65