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

Generating Dummy Data

If you want to generate auto-generated dummy data for a model in Django, you can use third-party libraries such as Faker or Factory Boy to create and populate instances of your model with random or realistic data.

First you would need to install the Faker library :

pip install Faker

alt text Next you can create a custom command to generate dummy data for the Person model. Click here to see how to create a custom command in Django.

Create a file named generate_Person_data in the app/management/commands folder and type in the following code to generate dummy data for Person model :

from django.core.management.base import BaseCommand
from faker import Faker
from modeldemo.models import Person

class Command(BaseCommand):
    help = 'Generate and insert dummy data for the Person model'

    def add_arguments(self, parser):
        parser.add_argument('--entries', type=int, help='The number of rows to insert')

    def handle(self, *args, **kwargs):
        fake = Faker()
        num_entries = kwargs['entries']

        if num_entries is None:
            self.stdout.write(self.style.SUCCESS('No --entries argument provided. Using the default of 10 entries.'))
            num_entries = 10

        for _ in range(num_entries):
            first_name = fake.first_name()
            last_name = fake.last_name()
            birth_date = fake.date_of_birth(minimum_age=18, maximum_age=80)

            Person.objects.create(
                first_name=first_name,
                last_name=last_name,
                birth_date=birth_date,
            )

        self.stdout.write(self.style.SUCCESS(f'Successfully inserted {num_entries} dummy entries for the Person model.'))

You can generate dummy data by running the following command :

python manage.py generate_Person_data --entries 1

alt text If the command is run without passing the entries argument, then 10 dummy records would be generated.

python manage.py generate_Person_data

alt text Now, if you try to get the Person objects, you will be able to see the dummy data in it.

Person.objects.all()

alt text Similarly, you can create any amount of dummy data for any of your models.