Now as the function and url has been created, in the workshop page a register button can be added, in order to handle the registration process.
<div class="text-center mt-4">
<form method="post" action="{% url 'register_workshop' workshop_slug=workshop.slug %}">
{% csrf_token %}
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white text-xl font-semibold py-2 px-4 rounded-md transition-colors duration-300">
Register
</button>
</form>
</div>
This would allow, the user to register for the workshop.
If a user tries to click the register button, without logging in, he would be redirected to the login page, else he would be registered for the workshop directly.
Here after he finishes his login, he is again redirected to the home page instead of directly going to the workshop registration page. This can be handled by updating the login page to redirect correctly.
In the authentication/views.py
file edit the login function :
def user_login(request):
if request.method == 'POST':
form = LoginForm(request.POST)
next = request.GET.get('next')
if form.is_valid():
email = form.cleaned_data.get('email')
password = form.cleaned_data.get('password')
user = authenticate(email=email, password=password)
if user is not None:
login(request, user)
if next:
return redirect(next)
return redirect('home')
else:
form = LoginForm()
return render(request, 'authentication/login.html', {'form': form})
Here the next parameter is taken from the url and is redirected based on that url. So now, if a user is redirected from some particular page, after he logs in he would again be redirected to the correct page automatically.
So now, after he clicks on the login he would be redirected to the workshop page, where he can click on register button and register for the workshop.
The workshop registration would be recorded with the date and time at which he registered.
A success message after registration can be added and along with it further validations needs to be done, as if the registration for the particular workshop has started or not, wether it has reached the maximum registration limit and if the user has already registered, then the button should be disabled and a message should be displayed as already registered.