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

Creating Abstract Model for Event

Let's create a event model which will store the basic details of the event that is going to be conducted. Also let's start that by creating a separate app named event.

The command for creating an app is as follows :

python manage.py startapp event

alt text And now as we have created another app we need to include this in the INSTALLED_APPS in settings.py file.

'event',

After this is done, you can open the event/models.py file and create an abstract model to store event information.

from django.db import models
from authentication.models import Department
from django.utils.text import slugify
from django.core.validators import MinValueValidator, MaxValueValidator

class AbstractEvent(models.Model):
    name = models.CharField(max_length=500, unique=True)
    year = models.PositiveIntegerField(
        validators=[
            MinValueValidator(2023),
            MaxValueValidator(9999)
        ]
    )
    website_link = models.CharField(max_length=1000, blank=True, null=True)
    target_audience = models.CharField(max_length=1000,null=True, blank=True)
    event_type = models.CharField(max_length=100, choices=[("offline", "Offline"),("online", "Online"),  ("both", "Both")], default="offline")
    mail_id = models.EmailField()
    start_date = models.DateTimeField()
    end_date = models.DateTimeField()
    registration_start_date = models.DateTimeField()
    registration_end_date = models.DateTimeField()
    department = models.ForeignKey(Department, on_delete=models.CASCADE)
    slug = models.SlugField(max_length=150, unique=True, blank=True)

    class Meta:
        abstract = True


    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(f"{self.name}")

        super().save(*args, **kwargs)

    def __str__(self):
        return self.name

Here this is used as a abstract model which stores some essential details such as,

  1. Name of the event.
  2. Year in which the event is taking place.
  3. Static Website Link if any for the event website.
  4. Target Audience for the event.
  5. The mode in which the event is going to take place, wether its an online event or an offline event.
  6. Official Mail Id for contact, regarding queries for the event.
  7. Then the start date and end date of events.
  8. Also the registration start date and registration end date for event is noted.
  9. A department Foreign Key of the event to note which department is conducting that particular event.
  10. And at last the slug field, which would be used in the urls. It allows the urls to be in human readable form instead of showing ids in the url.

In the Meta Class, this model is specified as abstract. This means no table would be created for this model in the database, and other classes can inherit the properities of this model.

The save() method is overrided in order to correctly modify the slug field.

So in the next section we would inherit this model to create registrations for workshops.