Django

College Event Registration Website

CampusConnect Introduction and Setup Configuring settings file for template, static and media files Setting up Tailwind Creating Custom User Model Creating Super User for CampusConnect Registering Custom User Model Search and Filter for User Model Serving Media Files During Development Categorizing Departments Linking Department with HOD Creating Abstract Model for Event Creating Model for Workshop Customizing Admin Page for Workshop Update in Model AbstractEvent Adding Instructor for Workshop Instructor Model Admin Page Adding Poster Field in Abstract Event Providing Access to HOD Access Update for HOD Restricting HOD Access to Particular Department AbstractEvent On Spot Registration Field Creating Workshop Object Creating and Linking Home Page Displaying Workshop on Home Page Styling Home Page Adding Workshop Detail Page Link Workshop Detail Page Workshop Detail Page Styling Workshop Instructor Details Workshop Detail Contact Contact Admin Page Many to Many Field for Contact Displaying Contact on Workshop Detail Page Adding Title for Workshop Detail Page Adding Gallery for Workshop Workshop Gallery Admin Page Displaying Gallery Images on Website Through Context Displaying Gallery Images on Website through template tags Authentication for users User Registration User Registration Submission Logout Functionality For User Login Functionality for User Model For Workshop Registration Workshop Registration Admin Page Register Workshop Function Register Button in Workshop Page Validations Before Workshop Registration Workshop Registration Closed Validaiton User Already Registered for Workshop Validation Workshop Registration Report From Admin Page Export using Library in Django Admin Extending Abstract Event for Hackathons

Workshop Registration Closed Validaiton

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. alt text