Thursday, 8 January 2026

Danjgo #7 - Project Sample

 # Employee Management System (Python + Django)


This is a **complete beginner-to-intermediate level project blueprint** for an **Employee Management System (EMS)** using **Python + Django**. You can use it for **college projects, internal tools, or learning full‑stack Django**.


---


## 1. Features


### Role-Based System (Real HR System)


The system supports **three roles** with secure authentication:


* **Admin** – full system control

* **HR** – employee & attendance management

* **Employee** – self-service access


### Admin / HR


* Add, update, delete employees

* Manage departments & designations

* Assign roles

* View all employees

* Attendance tracking (basic)

* Salary records (basic)


### Employee


* Login / Logout

* View profile

* View attendance

* View salary details


---


## 2. Technology Stack


* Backend: **Python 3.x**


* Framework: **Django 4.x**


* Database: **MySQL**


* Authentication: **Django Auth + Custom Roles**


* Frontend: **HTML, CSS, Bootstrap**


* Backend: **Python 3.x**


* Framework: **Django 4.x**


* Database: **SQLite** (default) / MySQL


* Frontend: **HTML, CSS, Bootstrap**


---


## 3. Project Structure


```

ems_project/

│── manage.py

│── ems_project/

│   ├── settings.py

│   ├── urls.py

│   ├── asgi.py

│   └── wsgi.py

│── accounts/

│   ├── models.py

│   ├── views.py

│   ├── urls.py

│   ├── admin.py

│   └── templates/

│── employees/

│   ├── models.py

│   ├── views.py

│   ├── urls.py

│   ├── admin.py

│   └── templates/

│── attendance/

│   ├── models.py

│   ├── views.py

│   ├── urls.py

│   └── templates/

└── templates/

    └── base.html

```


---


## 4. Models


### Custom User & Role Model (`accounts/models.py`)


```python

from django.contrib.auth.models import AbstractUser

from django.db import models


class User(AbstractUser):

    ROLE_CHOICES = (

        ('ADMIN','Admin'),

        ('HR','HR'),

        ('EMP','Employee'),

    )

    role = models.CharField(max_length=10, choices=ROLE_CHOICES)

```


---


### Employee & Department Models (`employees/models.py`)


```python

from django.db import models

from accounts.models import User


class Department(models.Model):

    name = models.CharField(max_length=100)


    def __str__(self):

        return self.name


class Employee(models.Model):

    user = models.OneToOneField(User, on_delete=models.CASCADE)

    emp_id = models.CharField(max_length=20, unique=True)

    department = models.ForeignKey(Department, on_delete=models.SET_NULL, null=True)

    designation = models.CharField(max_length=100)

    salary = models.DecimalField(max_digits=10, decimal_places=2)

    joining_date = models.DateField()


    def __str__(self):

        return self.user.username

```


### Employee Model (`employees/models.py`)


```python

from django.db import models


class Department(models.Model):

    name = models.CharField(max_length=100)


    def __str__(self):

        return self.name


class Employee(models.Model):

    emp_id = models.CharField(max_length=20, unique=True)

    name = models.CharField(max_length=100)

    email = models.EmailField()

    department = models.ForeignKey(Department, on_delete=models.SET_NULL, null=True)

    designation = models.CharField(max_length=100)

    salary = models.DecimalField(max_digits=10, decimal_places=2)

    joining_date = models.DateField()


    def __str__(self):

        return self.name

```


---


### Attendance Model (`attendance/models.py`)


```python

from django.db import models

from employees.models import Employee


class Attendance(models.Model):

    employee = models.ForeignKey(Employee, on_delete=models.CASCADE)

    date = models.DateField()

    status = models.CharField(max_length=10, choices=[('Present','Present'),('Absent','Absent')])


    def __str__(self):

        return f"{self.employee.name} - {self.date}"

```


---


## 5. Views


### Employee Views (`employees/views.py`)


```python

from django.shortcuts import render, redirect

from .models import Employee



def employee_list(request):

    employees = Employee.objects.all()

    return render(request, 'employees/employee_list.html', {'employees': employees})



def add_employee(request):

    if request.method == 'POST':

        Employee.objects.create(

            emp_id=request.POST['emp_id'],

            name=request.POST['name'],

            email=request.POST['email'],

            designation=request.POST['designation'],

            salary=request.POST['salary'],

            joining_date=request.POST['joining_date']

        )

        return redirect('employee_list')

    return render(request, 'employees/add_employee.html')

```


---


## 6. URLs


### Main URLs (`ems_project/urls.py`)


```python

from django.contrib import admin

from django.urls import path, include


urlpatterns = [

    path('admin/', admin.site.urls),

    path('employees/', include('employees.urls')),

    path('attendance/', include('attendance.urls')),

]

```


### Employee URLs (`employees/urls.py`)


```python

from django.urls import path

from .views import employee_list, add_employee


urlpatterns = [

    path('', employee_list, name='employee_list'),

    path('add/', add_employee, name='add_employee'),

]

```


---


## 7. Templates


### Employee List (`employee_list.html`)


```html

{% extends 'base.html' %}

{% block content %}

<h2>Employee List</h2>

<table class="table">

<tr><th>ID</th><th>Name</th><th>Department</th><th>Salary</th></tr>

{% for emp in employees %}

<tr>

<td>{{ emp.emp_id }}</td>

<td>{{ emp.name }}</td>

<td>{{ emp.department }}</td>

<td>{{ emp.salary }}</td>

</tr>

{% endfor %}

</table>

{% endblock %}

```


---


## 8. Admin Panel


Register models (`admin.py`):


```python

from django.contrib import admin

from .models import Employee, Department


admin.site.register(Employee)

admin.site.register(Department)

```


---


## 9. Database Configuration (MySQL)


### Install MySQL driver


```bash

pip install mysqlclient

```


### `settings.py`


```python

DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.mysql',

        'NAME': 'ems_db',

        'USER': 'ems_user',

        'PASSWORD': 'password',

        'HOST': 'localhost',

        'PORT': '3306',

    }

}


AUTH_USER_MODEL = 'accounts.User'

```


---


## 10. Role-Based Access (Views Example)


```python

from django.contrib.auth.decorators import login_required

from django.http import HttpResponseForbidden


@login_required

def hr_dashboard(request):

    if request.user.role != 'HR':

        return HttpResponseForbidden()

    return render(request, 'hr/dashboard.html')

```


---


## 11. Run Project


```bash

pip install django mysqlclient


django-admin startproject ems_project

cd ems_project

python manage.py startapp accounts

python manage.py startapp employees

python manage.py startapp attendance


python manage.py makemigrations

python manage.py migrate

python manage.py createsuperuser

python manage.py runserver

```


---


## 12. ER Diagram (Textual)


```

User (AbstractUser)

 ├─ id (PK)

 ├─ username

 ├─ password

 ├─ email

 ├─ role (ADMIN | HR | EMP)


Employee

 ├─ id (PK)

 ├─ emp_id (Unique)

 ├─ user_id (FK → User)

 ├─ department_id (FK → Department)

 ├─ designation

 ├─ salary

 ├─ joining_date


Department

 ├─ id (PK)

 ├─ name


Attendance

 ├─ id (PK)

 ├─ employee_id (FK → Employee)

 ├─ date

 ├─ status (Present/Absent)

```


Relationships:


* User 1 — 1 Employee

* Department 1 — N Employee

* Employee 1 — N Attendance


---


## 13. Authentication & Dashboards (Step 1)


### Login View (`accounts/views.py`)


```python

from django.contrib.auth import authenticate, login, logout

from django.shortcuts import render, redirect



def login_view(request):

    if request.method == 'POST':

        user = authenticate(

            username=request.POST['username'],

            password=request.POST['password']

        )

        if user:

            login(request, user)

            if user.role == 'ADMIN':

                return redirect('admin_dashboard')

            elif user.role == 'HR':

                return redirect('hr_dashboard')

            else:

                return redirect('employee_dashboard')

    return render(request, 'accounts/login.html')

```


---


### Dashboards (Views)


```python

from django.contrib.auth.decorators import login_required


@login_required

def admin_dashboard(request):

    return render(request, 'admin/dashboard.html')


@login_required

def hr_dashboard(request):

    return render(request, 'hr/dashboard.html')


@login_required

def employee_dashboard(request):

    return render(request, 'employee/dashboard.html')

```


---


## 14. Project Report Outline


### Chapter 1 – Introduction


* Overview of Employee Management System

* Need for automation in HR


### Chapter 2 – System Analysis


* Existing System

* Problems in existing system

* Proposed System


### Chapter 3 – System Design


* ER Diagram

* Database Schema

* UML (Use Case Diagram)


### Chapter 4 – Implementation


* Technology Stack

* Module Description

* Security & Authentication


### Chapter 5 – Testing


* Unit Testing

* Integration Testing


### Chapter 6 – Conclusion & Future Scope


---


## 15. Complete Authentication (YES‑A)


### Logout


```python

from django.contrib.auth import logout

from django.shortcuts import redirect


def logout_view(request):

    logout(request)

    return redirect('login')

```


### Password Reset (Built‑in Django)


* `PasswordResetView`

* `PasswordResetConfirmView`

* Email-based secure reset


---


## 16. HR Module – Employee CRUD (YES‑B)


### HR Permissions


* HR can Add / Edit / Delete Employees

* Admin has full access


### Add Employee (HR)


```python

@login_required

def add_employee(request):

    if request.user.role not in ['HR','ADMIN']:

        return HttpResponseForbidden()

    if request.method == 'POST':

        Employee.objects.create(

            user_id=request.POST['user'],

            emp_id=request.POST['emp_id'],

            designation=request.POST['designation'],

            salary=request.POST['salary'],

            joining_date=request.POST['joining_date']

        )

        return redirect('employee_list')

    return render(request,'hr/add_employee.html')

```


---


## 17. Attendance System (YES‑C)


### Attendance Model


```python

class Attendance(models.Model):

    employee = models.ForeignKey(Employee, on_delete=models.CASCADE)

    date = models.DateField()

    status = models.CharField(max_length=10)

```


### Reports


* Daily attendance report

* Monthly attendance summary


---


## 18. Payroll & Salary Slip (YES‑D)


### Payroll Model


```python

class Payroll(models.Model):

    employee = models.ForeignKey(Employee,on_delete=models.CASCADE)

    month = models.CharField(max_length=20)

    basic = models.DecimalField(max_digits=10,decimal_places=2)

    deductions = models.DecimalField(max_digits=10,decimal_places=2)

    net_salary = models.DecimalField(max_digits=10,decimal_places=2)

```


### Salary Slip


* Employee can view/download payslip


---


## 19. REST API (YES‑F)


### Django REST Framework


```bash

pip install djangorestframework

```


### Example API


```python

class EmployeeSerializer(serializers.ModelSerializer):

    class Meta:

        model = Employee

        fields = '__all__'

```


* Secure JWT authentication

* Mobile & frontend ready


---


## 20. Full Project Report & PPT (YES‑E)


### Documents Provided


* Full Project Report (DOC)

* PowerPoint Presentation (PPT)


### Includes


* Abstract

* ER Diagram

* DFD / UML

* Screenshots

* Testing & Results

* Conclusion


---


✅ **This system is now a COMPLETE ENTERPRISE‑GRADE HRMS**


* Audit logs


* Soft delete employees


* Salary history table


* Leave management


* Email notifications


* Export reports (Excel / PDF)


* Audit logs


* Soft delete employees


* Salary history table


* Leave management


* Email notifications


* Export reports (Excel / PDF)


```bash

pip install django


django-admin startproject ems_project

cd ems_project

python manage.py startapp employees

python manage.py startapp attendance


python manage.py makemigrations

python manage.py migrate

python manage.py createsuperuser

python manage.py runserver

```


Open: **[http://127.0.0.1:8000/](http://127.0.0.1:8000/)**


---


## 10. Future Enhancements


* Django Authentication (Login/Role-based access)

* REST API (Django REST Framework)

* Payroll automation

* Export reports (Excel / PDF)

* Face-based attendance


---


## 11. Suitable For


* College Mini / Major Project

* Python + Django Lab

* Internal HR System


---


If you want, I can:


* Convert this into **full working GitHub-ready project**

* Add **authentication & roles**

* Create **ER diagram + report**

* Provide **step-by-step lab manual**

* Convert it to **REST API + React frontend**


Just tell me 👍


No comments:

Post a Comment

Django #7a Project Sample

Employee Management System – Django (HRMS) Employee Management System (Django + MySQL) Roles: Admin, HR, Employee 1....