V
V
Vladislav Sklyar2015-08-21 12:32:20
Django
Vladislav Sklyar, 2015-08-21 12:32:20

Registration by invite code?

Good afternoon toaster!! There was a goal to create invitations to the site. I made an invitation model with the following fields: email, user(who invites), code(invite code), is_accept(whether the invite is accepted). The invitation code is added at the end of the sent link in the invitation.
Question: how to set up the link in url.py so that it can work and if the code is and is not?
Example:
When you go to /register/, a registration form appears.
When you go to /register/some_invite_code/, a registration form appears and is_accept = True is entered into the database.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav Sklyar, 2015-08-21
@VladSkliar

I solved the problem like this:
I made two pages:

  • Page for invitees
    url(r'^register/(?P<invite_code>[A-Za-z]+)/$', views.InviteRegisterFormView.as_view(),
          name='invite_register'),

  • Page for uninvited
    url(r'^register/$', views.RegisterFormView.as_view(),
          name='register'),

    In cbv InviteRegisterFormView inherited from RegisterFormView. And used a variable
    invite_code = self.kwargs['invite_code']
    invite = get_object_or_404(UserInvite, code=invite_code)
    invite.is_accept = True
    invite.save()

    Now an invitation from different users can come to the mail, the server will determine by whose link you registered.

Z
zelsky, 2015-08-21
@zelsky

Во вью проверять если не использован инвайт код.
Если не использован в модель юзера в поле рефер добавлять айди кому пренадлежит ссилка тоетсь айди рефера.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question