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

Register Button in Workshop Page

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

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