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

Adding Instructor for Workshop

If a workshop is being conducted, there would be some speaker or instructor for a particular workshop. There may be one or more than one instructors for each workshop. So in this cases when we are not sure about how many fields are needed, it is always best to go for another model and add a foreign key to this model. So we are going to do the same here.

In the event/models.py file, we will create another model to assign instructors for workshops:

class WorkshopInstructor(models.Model):
    workshop = models.ForeignKey(Workshop, on_delete=models.CASCADE)
    instructor_name = models.CharField(max_length=255)
    company_name = models.CharField(max_length=255)
    designation = models.CharField(max_length=255)
    linked_in_url = models.URLField(blank=True, null=True)
    image = models.ImageField(upload_to="instructor_images/", null=True, blank=True)

    def __str__(self):
        return f"{self.instructor_name}-{self.company_name}"

This model we will be using to note down the details of the instructor of the workshop.

Note : Another type of schema also can be used in this case. The instructor's table can be kept as a separate entitiy where all the details of all instructors will be recorded and in the workshop model a ManyToMany field can be set to note the instructors of that particular workshop. This avoids duplicate entries in the database. You can try implementing it that way in your project.

So continuing only the model has been created, in order to make changes in the database, migrations need to be run.

python manage.py makemigrations
python manage.py migrate

alt text After this the models have been created in the database.

In the next section, you would see how to register this model in the admin page.