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:

# Three Unconventional Sales Techniques to Boost Your Closing Rate

Discover three unique sales strategies to enhance your closing rate while building authentic relationships with clients.

Why Chainlink (LINK) Deserves Your Attention in the Crypto Space

Explore why Chainlink (LINK) is an undervalued mid-cap token with significant potential in the crypto market.

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.

Overcoming the Greatest Hurdles to Innovation

Exploring how mindset and resistance to change hinder innovation.

Harnessing Boredom for Innovative Thinking and Creativity

Exploring how embracing boredom can enhance creativity and foster innovative ideas in our fast-paced world.

# Are Vitamins Truly Essential? Insights for Health-Conscious Individuals

Many wonder if vitamins are necessary for good health. Recent studies suggest that for most healthy adults, they may not be needed.

The Surprising Connection Between Hair Color and Aging

Explore the intriguing link between hair color changes and aging, highlighting the role of biochemical processes and lifestyle choices.

Cruise Accelerates While Tesla Struggles: Analyzing the Competition

Explore the competitive landscape between Cruise and Tesla in the race toward autonomy, and what it means for investors.