In the previous section, before the user registered for the workshop, we had checked wether the registration for the particular workshop was open or not. Similarly, we need to check wether the register is closed or not, before we allow the user to register for the workshop. We can add another method in the AbstractEvent model to do this.
In the AbstractEvent
model in event/models.py
file :
def is_registration_closed(self):
if self.max_registrations<=Workshopregistration.objects.filter(workshop=self).count():
return True
if self.registration_end_date <= timezone.now():
return True
return False
Here, both conditions have been checked, wether it has crossed the max registrations allowed for a particular workshop and as well as wether the registration_end_date has reached.
So if any of the conditions is True, it won't allow for the workshop registration.
Now the condition also needs to be handled in the workshop_detail
page to display the message.
{% if not workshop.is_registration_open %}
<div class="text-center mt-4">
<button class="bg-gray-500 text-white font-semibold py-2 px-4 rounded-md cursor-not-allowed" disabled>
The workshop Registration is not open yet !!.
</button>
</div>
{% elif workshop.is_registration_closed %}
<div class="text-center mt-4">
<button class="bg-gray-500 text-white font-semibold py-2 px-4 rounded-md cursor-not-allowed" disabled>
The Registration for the Workshop has been closed.
</button>
</div>
{% else %}
<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>
{% endif %}
So now, here both the conditions are being checked before the workshop registration.