spirosgyros.net

Building a Simple HR Management System with Django: A Recap

Written on

Chapter 1: Project Overview

We have successfully developed a straightforward human resource management system (HRMS) tool. This project serves as an excellent starting point for developers venturing into Python, Django, and web development.

Project Highlights

Although HRMS v1 is relatively simple, there are several noteworthy aspects:

  1. Django MVT Architecture: This project utilizes the standard Model-View-Template (MVT) architecture. The model defines the data structure, the view manages the request handling and data processing, while the template structures the webpage and displays the data.
  2. PostgreSQL Database Interaction: The database operations have been encapsulated within a class that provides standard database methods.
  3. Executing Raw SQL Queries: The system supports executing raw SQL queries for database manipulation.
  4. Error Handling: We have implemented error handling for database operations.

Here's an example of how we connect to the PostgreSQL database using Python:

import psycopg2

class PSQLConn:

def __init__(self, conn_info):

self.conn_info = conn_info

self.result = [] # to store database results

self.flag = 0 # to indicate success (1) or failure (0)

self.msg = "" # to hold error messages

def get_db_data(self, sql):

"""

Retrieves data from the database using the provided SQL query.

"""

psql_conn = psycopg2.connect(

database=self.conn_info["NAME"],

host=self.conn_info["HOST"],

port=self.conn_info["PORT"],

user=self.conn_info["USER"],

password=self.conn_info["PASSWORD"],

)

try:

cursor = psql_conn.cursor()

cursor.execute(sql)

self.result = list(cursor.fetchall())

self.flag = 1

cursor.close()

psql_conn.close()

except Exception as e:

self.flag = 0

self.msg = str(e)

Connecting Frontend to Backend

Through form submissions and event handlers, we facilitate the interaction between the frontend and backend. We also leverage regular expressions for data validation prior to submission.

Here’s a snippet of jQuery that validates form fields:

$("#editform").submit(function () {

let name = $("#editform input[name='name']").val().trim();

if (name.length === 0) {

alert("Name cannot be empty");

return false;

}

// Gender validation

let gender = $("#editform select[name='gender']").val().trim();

if (!["Male", "Female", "Other"].includes(gender)) {

alert("Gender must be one of: Male, Female, or Other");

return false;

}

// Birthday validation

let birthday = $("#editform input[name='birthday']").val().trim();

if (!birthday.match(/^d{2}-d{2}-d{4}$/)) {

alert("Birthday must be in the format mm-dd-yyyy e.g., 05-31-2024.");

return false;

}

// Additional validations for mobile, email, and address...

return true;

});

Future Improvements

There are several areas for enhancement in upcoming versions:

  1. ORM (Object Relational Mapping): In future updates, we will replace raw SQL queries with ORM, which is a more elegant way to handle database interactions in Django.
  2. Ajax Implementation: To enhance user experience, we aim to integrate Ajax, allowing our HRMS to update content asynchronously without needing to reload the entire webpage.

Step by step, we are building something remarkable! Stay tuned for Progressive Django v2.

Thank you for your support!

We appreciate your involvement in the In Plain English community! Don't forget to clap and follow the writer!

Follow us on our social platforms: X | LinkedIn | YouTube | Discord | Newsletter. For more content, check out Stackademic | CoFeed | Venture | Cubed.

See more at PlainEnglish.io.

Chapter 2: Educational Videos

To further enhance your understanding of web development, we have included some insightful YouTube videos below.

The first video, "Web Development In 2023 - A Practical Guide," offers a thorough overview of the current landscape of web development, covering essential tools and frameworks.

The second video, "100 Days of Code - Web Development Bootcamp - Full Course: Day 1 - 8," provides a comprehensive guide through the initial stages of web development.

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

Smart Money Management: Insights from Suze Orman’s Philosophy

Explore Suze Orman's practical financial wisdom on needs vs. wants and the importance of investing for your future.

All-In-One Resource for Writing, Freelancing, and Entrepreneurship

Discover a comprehensive collection of articles on writing, freelancing, and entrepreneurship in one convenient location.

The Enduring Mystery of the McMinnville UFO Photos

In 1950, two Oregon farmers captured UFO photos that continue to baffle experts and ignite public interest decades later.

Transformative Benefits of Walking: Enhancing Health and Spirit

Discover how walking can enhance your physical health, mental clarity, emotional balance, and spiritual growth.

Unlock the Secrets of Radiant Skin with Niacinamide Benefits

Explore the remarkable effects of niacinamide on skin health, including its role in hydration, acne treatment, and aging prevention.

Maximizing Your Content: Transform One Blog Post into 12 Pieces

Discover how to effectively repurpose a single blog post into multiple content formats to enhance your reach and efficiency.

Creating a Fulfilling Life: Moving Beyond Conventional Goals

Explore the pitfalls of conventional goals and how to create a life that resonates with your true desires.

Design Your AI-Generated eBook Without Spending a Dime

Discover how to create and publish your AI-assisted eBook for free, maximizing income potential without upfront expenses.