0

How can i increase the point of inviter when he has referred other to join. Point will be increase when refer is accepted. I could make the referral but could not increase the point when refer is accepted by the user to whom the refer was send by inviter.

Here is my code

class Invitation(models.Model):
    email = models.EmailField(unique=True, verbose_name=_("e-mail Address"))
    invite_code = models.UUIDField(default=uuid.uuid4, unique=True)
    points = models.PositiveIntegerField(default=5)
    request_approved = models.BooleanField(default=True, verbose_name=_('request accepted'))

    def __str__(self):
        return "Invite: {0}".format(self.email)

class Referral(models.Model):
    referred_by = models.ForeignKey(Invitation, related_name="sharer", null=False, blank=False)
    referred_to = models.EmailField(unique=True, null=False, blank=False)
    refer_code = models.UUIDField(default=uuid.uuid4, unique=True)
    refer_accepted = models.BooleanField(default=False)


def referInvitation(request, invite_code):
    try:
        # invite_id = request.session['invite_id']
        obj = Invitation.objects.get(invite_code=invite_code)
    except:
        obj = None
    form = ReferForm(request.POST or None)
    if form.is_valid():
        referred_to = form.cleaned_data.get('referred_to')
        print ('referred_to', referred_to)
        if not obj == None:
            new_refer = Referral(referred_by=obj, referred_to=referred_to)
            new_refer.save()
            subject = "Request to Join Connyct"
            from_email=None
            message = "You have been invited by {0}".format(obj.email)
            to_email=[referred_to]
            send_mail(subject, message, from_email, to_email, fail_silently=True)
    context = {"form": form}
    return render(request, 'refer/refer.html', context)
pythonBeginner
  • 781
  • 2
  • 12
  • 27

1 Answers1

0

Send a accept/signup link along with the email message. After the user signup/accepted is complete then only increase count of the person who has referred, by doing the following:

obj.points += 1

Abijith Mg
  • 2,647
  • 21
  • 35
  • Do i have to increase the points like you have said in middlewares? Because in my case when i refer you to join, you will get an email to join. When you click that link, a count has to be increased. – pythonBeginner Mar 20 '17 at 12:13
  • Design a link/url such that it can pass user objects. Like www.sample.com/register//. This link should eventually display a form to fetch the new user details and also increase the count simultaneously. – Abijith Mg Mar 20 '17 at 12:21