0

I am working on a cashback website. Right now the code is just adding the current balance of the referred user($0) to the balance of the referrer, how can i link the two users so that a fraction of the referred user's future earnings will be added to the balance of the referrer

def referral_registerPage(request, slug):

form = CreateUserForm

if request.method == 'POST':

    customers = Customer.objects.all()

    form = CreateUserForm(request.POST)
    if form.is_valid():
        user = form.save()
        username = form.cleaned_data.get('username')
        messages.success(request,'Account was created for ' + username)

        '''Get slug that was used to register account.'''
        user_slug = slug

        '''get user id by splitting user_slug, b = user id'''
        a,b = user_slug.split('-')

        '''customer that owns the referral link'''
        customer = customers.get(user=b)

        '''customer that registered through the referral link'''
        referred = customers.get(user=user)

        payment = customer.payment #payment details of the customer
        payment.current_balance +=  referred.payment.current_balance
        payment.save()

model i'm trying to update

class Payment(models.Model):

customer = models.OneToOneField(Customer, on_delete=models.CASCADE, 
null=True, default=None)

total_amount_paid = models.DecimalField(max_digits=20,decimal_places=2, 
null=True, default=0)

current_balance = models.DecimalField(max_digits=20,decimal_places=2, 
null=True, default=0)

confirmed_orders = models.CharField(max_length=100, null=True, default=0)
  • there could be a lot of ways to implement this, one possible solution would be to have marketing slugs for users that other users can use while signing up. what have you tried so far? can you share some code? – Aarif May 09 '20 at 18:56
  • I haven't tried anything for now, can you please tell me how to implement the marketing slug? – Oluwatobi Femi May 09 '20 at 19:48
  • in very simple terms you can implement a signup endpoint and extract the slug from the URL to identify which user referred this new user and apply the business logic accordingly, a simple google search would yield tutorials for implementing slug field, you should start with that and post if you face a specific coding problem. . take a look here (https://stackoverflow.com/a/8492693/6027876) – Aarif May 10 '20 at 06:57
  • Aarif, i just updated the question, right now the code is just adding the current balance of the referred customer ($0) to the balance of the referrer, how can i link the two users so that a fraction of the referred user's future earnings will be added to the balance of the referrer – Oluwatobi Femi May 10 '20 at 13:24

0 Answers0