在他/她引用其他人之后增加邀请者的点数

时间:2017-03-20 12:01:40

标签: python django django-models django-views

当他引用其他人加入时,我怎样才能增加邀请者的点数。接受推荐时,积分将增加。我可以进行推荐,但是当邀请人发送推荐的用户接受推荐时,无法增加推荐。

这是我的代码

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)

1 个答案:

答案 0 :(得分:0)

发送接受/注册链接以及电子邮件。用户注册/接受完成后,通过执行以下操作,仅增加已推荐人员的计数:

obj.points += 1