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

Categorizing Departments

In a college, multiple departments will be there and each department would have their separate events. We shall create a separate model named department and add a relation with it, as to know by which department a particular event is being conducted. Like this it would be easy to keep track of department wise events and also apply filters in backend.

So we shall start by creating a model in authentication/models.py named Department.

class Department(models.Model):
    abbr = models.CharField(max_length=20)
    name = models.CharField(max_length=255)

    def __str__(self):
        return self.abbr

    class Meta:
        ordering = ['abbr']

Here two fields are there, one which contains the short form of the department and the next the department name as whole. The string function is overrided to return the abbreviation of the department, and also ordered with the department while returning the results.

To create a table in the database you need to migrate the changes. This can be done by using the following commands :

python manage.py makemigrations
python manage.py migrate

alt text The table has been created in the database successfully. You can continue and register the model in admin page to easily modify and edit the model.

@admin.register(Department)
class DepartmentAdmin(admin.ModelAdmin):
    list_display= ('abbr', 'name')
    search_fields = ('abbr', 'name')

This will make it easy to add departments for the admin. Now when you open the admin page, you will be able to see another model named department and can view, add, edit and delete its entries. alt text You can similarly add a department by clicking the button. alt textClicking the save button will insert the row into the table. alt text The department model is created successfully. The department models needs to be linked with each hod's in order to verify their department while entring an event inside the portal.