0% found this document useful (0 votes)
3 views

Ajp

The document outlines an Office Employee Management System built using Django, detailing the project structure, settings, models, views, and templates. It includes functionalities for viewing, adding, filtering, and removing employee details. The code snippets demonstrate the implementation of various components such as models for Employee, Department, and Role, as well as the corresponding views and HTML templates.

Uploaded by

chavanleena33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Ajp

The document outlines an Office Employee Management System built using Django, detailing the project structure, settings, models, views, and templates. It includes functionalities for viewing, adding, filtering, and removing employee details. The code snippets demonstrate the implementation of various components such as models for Employee, Department, and Role, as well as the corresponding views and HTML templates.

Uploaded by

chavanleena33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

ASSIGNMENT NO-4

OUTPUT-
Office Employee Management System-

View All Employee Details-


Add An Employee-

Add An Employee-
Filter An Employee Details-

CODE-
Setting.py-
""" # Build paths inside the project like this:
BASE_DIR / 'subdir'.
Django settings for office_emp_proj project.
import os
BASE_DIR =
Generated by 'django-admin startproject' using Path(__file__).resolve().parent.parent
Django 5.0.6.
TEMP_DIR=os.path.join(BASE_DIR,'template')

For more information on this file, see


https://docs.djangoproject.com/en/5.0/topics/sett
ings/ # Quick-start development settings - unsuitable
for production
# See
For the full list of settings and their values, see https://docs.djangoproject.com/en/5.0/howto/dep
loyment/checklist/
https://docs.djangoproject.com/en/5.0/ref/setting
s/
""" # SECURITY WARNING: keep the secret key
used in production secret!

from pathlib import Path


SECRET_KEY = 'django-insecure-
&eccoixeslij0gvgg@abx_u^ckal3g7&=hsfi_2l4 'django.middleware.csrf.CsrfViewMiddleware',
bgvi-@_58'
'django.contrib.auth.middleware.Authentication
Middleware',
# SECURITY WARNING: don't run with debug
turned on in production!
'django.contrib.messages.middleware.MessageM
DEBUG = True iddleware',

ALLOWED_HOSTS = [] 'django.middleware.clickjacking.XFrameOption
sMiddleware',
]

# Application definition
ROOT_URLCONF = 'office_emp_proj.urls'

INSTALLED_APPS = [
TEMPLATES = [
'django.contrib.admin',
{
'django.contrib.auth',
'BACKEND':
'django.contrib.contenttypes', 'django.template.backends.django.DjangoTempl
'django.contrib.sessions', ates',

'django.contrib.messages', 'DIRS': [TEMP_DIR],

'django.contrib.staticfiles', 'APP_DIRS': True,

'emp_app' 'OPTIONS': {

] 'context_processors': [

'django.template.context_processors.debug',
MIDDLEWARE = [
'django.template.context_processors.request',
'django.middleware.security.SecurityMiddleware
',
'django.contrib.auth.context_processors.auth',

'django.contrib.sessions.middleware.SessionMid
dleware', 'django.contrib.messages.context_processors.me
ssages',

'django.middleware.common.CommonMiddlewa ],
re', },
}, 'NAME':
'django.contrib.auth.password_validation.Minim
]
umLengthValidator',
},
WSGI_APPLICATION = {
'office_emp_proj.wsgi.application'
'NAME':
'django.contrib.auth.password_validation.Comm
onPasswordValidator',

# Database },

# {
https://docs.djangoproject.com/en/5.0/ref/setting 'NAME':
s/#databases 'django.contrib.auth.password_validation.Numer
icPasswordValidator',

DATABASES = { },

'default': { ]

'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
} # Internationalization

} #
https://docs.djangoproject.com/en/5.0/topics/i18
n/

# Password validation LANGUAGE_CODE = 'en-us'


#
https://docs.djangoproject.com/en/5.0/ref/setting
s/#auth-password-validators TIME_ZONE = 'UTC'

AUTH_PASSWORD_VALIDATORS = [ USE_I18N = True

{
'NAME': USE_TZ = True
'django.contrib.auth.password_validation.UserAt
tributeSimilarityValidator',
},
# Static files (CSS, JavaScript, Images)
{
#
https://docs.djangoproject.com/en/5.0/howto/stat name=models.CharField(max_length=100,null=
ic-files/ False)

STATIC_URL = 'static/' def __str__(self):


return self.name
# Default primary key field type
# class Employee(models.Model):
https://docs.djangoproject.com/en/5.0/ref/setting
s/#default-auto-field
first_name=models.CharField(max_length=100,
null=False)
DEFAULT_AUTO_FIELD =
'django.db.models.BigAutoField' last_name=models.CharField(max_length=100)

dept=models.ForeignKey(Department,on_delete
=models.CASCADE)

Models.py salary=models.IntegerField(default=0)

from django .db import models bonus=models.IntegerField(default=0)

role=models.ForeignKey(Role,on_delete=model
# Create your models here . s.CASCADE)
class Department(models.Model): phone=models.IntegerField(default=0)
hire_date=models.DateField()
name=models.CharField(max_length=100,null=
False)
def __str__(self):
locations=models.CharField(max_length=100)
return "%s %s %s
"%(self.first_name,self.last_name,self.phone)

def __str__(self):
return self.name

Admin.py-
from django.contrib import admin
class Role(models.Model): from . models import
Employee,Role,Department
# Register your models here. from emp_app import views
admin.site.register(Employee)
admin.site.register(Role) urlpatterns = [
admin.site.register(Department) path('',views.index,name='index'),
path('all_emp', views.all_emp,
name='all_emp'),
path('add_emp', views.add_emp,
Urls.py- name='add_emp'),

"""
path('remove_emp',views.remove_emp,name='re
URL configuration for office_emp_proj project. move_emp'),
path('remove_emp/<int:emp_id>',
The `urlpatterns` list routes URLs to views. For views.remove_emp, name='remove_emp'),
more information please see: path('filter_emp', views.filter_emp,
name='filter_emp'),
https://docs.djangoproject.com/en/5.0/topics/http ]
/urls/
Examples:
Function views
Views.py
1. Add an import: from my_app import views
from django.shortcuts import
2. Add a URL to urlpatterns: path('',
render,HttpResponse
views.home, name='home')
from .models import Employee ,Role,
Class-based views
Department
1. Add an import: from other_app.views
from datetime import datetime
import Home
from django.db.models import Q
2. Add a URL to urlpatterns: path('',
Home.as_view(), name='home') # Create your views here.
Including another URLconf def index(request):
1. Import the include() function: from return render(request,'index.html')
django.urls import include, path
2. Add a URL to urlpatterns: path('blog/',
include('blog.urls')) def all_emp(request):

""" emps=Employee.objects.all()

from django.contrib import admin context={

from django.urls import path,include 'emps':emps


} try:
print(context)
emp_to_be_removed=Employee.objects.get(id=
emp_id)
return render(request,'view_all.html',context) emp_to_be_removed.delete()
return HttpResponse("Employee
def add_emp(request): Removed Successfully")

if request.method=="POST":
first_name=request.POST['first_name'] except:

last_name = request.POST['last_name']
salary = int(request.POST['salary']) return HttpResponse("Please Enter A
Valid EMP ID")
bonus = int(request.POST['bonus'])
emps = Employee.objects.all()
phone = int(request.POST['phone'])
context={
dept = int(request.POST['dept'])
'emps':emps
role = int(request.POST['role'])
}

new_emp=Employee(first_name=first_name,last return
_name=last_name,salary=salary,bonus=bonus,ph render(request,'remove_emp.html',context)
one=phone,dept_id=dept,role_id=role,hire_date
=datetime.now())
def filter_emp(request):
new_emp.save()
if request.method=="POST":
return HttpResponse('Employee added
Successfully') name = request.POST['name']
elif request.method=="GET": dept =request . POST['dept']
return render(request,'add_emp.html') role =request. POST['role']
else: emps=Employee.objects.all()
return HttpResponse('An Exception
Occured! Emplyoee Has Not Been Added')
if name:

def remove_emp(request,emp_id=0): emps=emps.filter(Q(first_name__icontains


=name) | Q(last_name__icontains =name))

if emp_id:
if dept:
<meta charset="utf-8">
emps=emps.filter(dept__name__icontains=dept)
<meta name="viewport"
content="width=device-width, initial-scale=1">
if role: <title>Office Employee Management</title>
<link
emps=emps.filter(role__name__icontains=role) href="https://cdn.jsdelivr.net/npm/bootstrap@5.
3.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-
4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQ
context={ NGCHeKRQN+PtmoHDEXuppvnDJzQIu9"
crossorigin="anonymous">
<style>
'emps':emps
.container-fluid{
background-color: #00d6c2;
}
}
return
render(request,'view_all.html',context)
#bg{

background-color: aqua;

elif request.method=='GET': }

return render(request,'filter_emp.html') </style>


</head>

else:
return HttpResponse('An Exception <body id="bg">
Occurred!') <div class="container">
<header>
<h1>OFFICE EMPLOYEE
Index.html- MANAGEMENT SYSTEM</h1>
<hr>
<!doctype html>
<nav class="navbar navbar-expand-lg
<html lang="en">
bg-body-tertiary" style="background-color:
pink">

<head> <div class="container-fluid">


<a class="navbar-brand" <a class="nav-link"
href="#">OEMS</a> href="/filter_emp" role="button">Filter
Employee Details</a>
<button class="navbar-toggler"
type="button" data-bs-toggle="collapse" </li>
data-bs-
target="#navbarSupportedContent" aria-
controls="navbarSupportedContent" </ul>

aria-expanded="false" aria- <form class="d-flex"


label="Toggle navigation"> role="search">

<span class="navbar-toggler- <input class="form-control


me-2" type="search" placeholder="Search" aria-
icon"></span>
label="Search">
</button>
<button class="btn btn-outline-
<div class="collapse navbar- success" type="submit">Search</button>
collapse" id="navbarSupportedContent">
</form>
<ul class="navbar-nav me-auto
mb-2 mb-lg-0">
<li class="nav-item"> </div>

<a class="nav-link active" </div>


aria-current="page" href="/all_emp">Home</a> </nav>
</li> </header>
<li class="nav-item">
<a class="nav-link" </div>
href="/all_emp" role="button">View All
Employee</a>
</li> <!-- Content here -->

<li class="nav-item"> </div>

<a class="nav-link"
href="/add_emp" role="button">Add An <script
Employee</a> src="https://cdn.jsdelivr.net/npm/[email protected].
</li> 1/dist/js/bootstrap.bundle.min.js"

<li class="nav-item"> integrity="sha384-


HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBN
<a class="nav-link" S5n7C8IVInixGAoxmnlMuBnhbgrkm"
href="/remove_emp" role="button">Remove An
Employee</a> crossorigin="anonymous"></script>

</li> </body>

<li class="nav-item">
</html> }
</style>
</head>

Add_emp.html-
<!DOCTYPE html> <body id="bg">

<html lang="en"> <div class="container">


<!-- Content here -->

<head> <h1>Add An Emplyoee!</h1>

<meta charset="UTF-8"> <hr>

<title>Add_Employee</title> <form action="/add_emp" method="post">

<link {% csrf_token %}
href="https://cdn.jsdelivr.net/npm/bootstrap@5.
3.1/dist/css/bootstrap.min.css" rel="stylesheet"
<label for="first_name">First
integrity="sha384- Name</label><br>
4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQ
NGCHeKRQN+PtmoHDEXuppvnDJzQIu9" <input type="text" id="first_name"
crossorigin="anonymous"> name="first_name"
value="{{first_name}}"><br>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]. <label for="last_name">Last
1/dist/js/bootstrap.bundle.min.js" Name</label><br>

integrity="sha384- <input type="text" id="last_name"


HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBN name="last_name"
S5n7C8IVInixGAoxmnlMuBnhbgrkm" value="{{last_name}}"><br>

crossorigin="anonymous"></script> <label for="salary">Salary</label><br>

<style> <input type="number" id="salary"


name="salary" value="{{salary}}"><br>
.container{
<label for="phone">Phone</label><br>
background-color: #00d6c2;
<input type="number" id="phone"
height: 530px; name="phone" value="{{phone}}"><br>
} <label
for="dept">Department</label><br>

#bg{ <input type="number" id="dept"


name="dept" value="{{dept}}"><br>
<label for="role">Role</label><br>
background-color: aqua;
<input type="number" id="role" integrity="sha384-
name="role" value="{{role}}"><br> HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBN
S5n7C8IVInixGAoxmnlMuBnhbgrkm"
<label for="bonus">Bonus</label><br>
crossorigin="anonymous"></script>
<input type="number" id="bonus"
name="bonus" value="{{bonus}}"><br> <style>
<hr> .container{
<button type="submit" class="btn btn- background-color: #00d6c2;
primary">Submit</button>
height: 350px;
</form>
padding: 10px;
</div>
}

</body>
#bg{

</html>
background-color: aqua;
}
</style>
Filter_emp.html- </head>
<!DOCTYPE html>
<html lang="en"> <body id="bg">
<div class="container">
<head> <!-- Content here -->
<meta charset="UTF-8"> <h1>Filter An Emplyoee Details!</h1>
<title>Filter Employee</title> <hr>
<link <form action="/filter_emp"
href="https://cdn.jsdelivr.net/npm/bootstrap@5. method="post">
3.1/dist/css/bootstrap.min.css" rel="stylesheet"
{% csrf_token %}
integrity="sha384-
4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQ
NGCHeKRQN+PtmoHDEXuppvnDJzQIu9"
<label for="name">Employee First/Last
crossorigin="anonymous">
Name</label><br>
<script
<input type="text" id="name"
src="https://cdn.jsdelivr.net/npm/[email protected].
name="name" value="{{name}}"><br>
1/dist/js/bootstrap.bundle.min.js"
<label <script
for="dept">Department</label><br> src="https://cdn.jsdelivr.net/npm/[email protected].
1/dist/js/bootstrap.bundle.min.js"
<input type="text" id="dept"
name="dept" value="{{dept}}"><br> integrity="sha384-
HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBN
<label for="role">Role</label><br> S5n7C8IVInixGAoxmnlMuBnhbgrkm"
<input type="text" id="role" crossorigin="anonymous"></script>
name="role" value="{{role}}"><br>
<style>
<hr>
.container{
<button type="submit" class="btn btn-
primary">Submit</button> background-color: #00d6c2;
</form> height: 200px;
</div> padding: 10px;
}
</body>
#bg{
</html>
background-color: aqua;
}

Remove_emp.html- </style>

mon </head>

<!DOCTYPE html>
<html lang="en"> <body id="bg">
<div class="container">

<head>
<meta charset="UTF-8"> <h1>Remove An Employee! </h1>

<title>Remove Employee</title> <hr>

<link <button class="btn btn-primary dropdown-


href="https://cdn.jsdelivr.net/npm/bootstrap@5. toggle" type="button" data-bs-
3.1/dist/css/bootstrap.min.css" rel="stylesheet" toggle="dropdown" aria-expanded="false">

integrity="sha384- choose Employee to Be Removed


4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQ </button>
NGCHeKRQN+PtmoHDEXuppvnDJzQIu9"
crossorigin="anonymous"> <ul class="dropdown-menu">
crossorigin="anonymous"></script>
{% for emp in emps%} </head>
<li><a class="dropdown-item"
href="/remove_emp/{{emp.id}}">{{emp.first_n
ame}}{{emp.last_name}}</a></li> <body>

{% endfor %} <nav class="navbar navbar-expand-lg bg-


body-tertiary">
<div class="container-fluid">
</ul>
<a class="navbar-brand"
</div> href="#">Navbar</a>
</body> <button class="navbar-toggler"
type="button" data-bs-toggle="collapse"
</html>
data-bs-
target="#navbarSupportedContent" aria-
controls="navbarSupportedContent" aria-
expanded="false"
aria-label="Toggle navigation">
Test.html-
<span class="navbar-toggler-
<!DOCTYPE html> icon"></span>

<html lang="en"> </button>


<div class="collapse navbar-collapse"
id="navbarSupportedContent">
<head>
<ul class="navbar-nav me-auto mb-2
<meta charset="UTF-8"> mb-lg-0">
<title>Title</title> <li class="nav-item">
<link <a class="nav-link active" aria-
href="https://cdn.jsdelivr.net/npm/bootstrap@5. current="page" href="#">Home</a>
3.1/dist/css/bootstrap.min.css" rel="stylesheet"
</li>
integrity="sha384-
4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQ <li class="nav-item">
NGCHeKRQN+PtmoHDEXuppvnDJzQIu9"
<a class="nav-link"
crossorigin="anonymous">
href="#">Link</a>
<script
</li>
src="https://cdn.jsdelivr.net/npm/[email protected].
1/dist/js/bootstrap.bundle.min.js"
integrity="sha384- </ul>
HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBN
S5n7C8IVInixGAoxmnlMuBnhbgrkm" <form class="d-flex" role="search">
<input class="form-control me-2" <style>
type="search" placeholder="Search" aria-
.container{
label="Search">
<button class="btn btn-outline- background-color: #00d6c2;
success" type="submit">Search</button> height: 500px;
</form> padding: 10px;
</div> }
</div>
</nav> #bg{
</body>
</html> background-color: aqua;
}
</style>
View_all.html- </head>

<!DOCTYPE html>
<html lang="en"> <body id="bg">
<div class="container">

<head> <!-- Content here -->

<meta charset="UTF-8"> <h1>All Employee Details</h1>

<title>View Employee</title> <hr>

<link <table class="table table-info table-


href="https://cdn.jsdelivr.net/npm/bootstrap@5. striped">
3.1/dist/css/bootstrap.min.css" rel="stylesheet"
<thead>
integrity="sha384-
<tr>
4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQ
NGCHeKRQN+PtmoHDEXuppvnDJzQIu9" <th scope="col">ID</th>
crossorigin="anonymous">
<th scope="col">First Name</th>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]. <th scope="col">Last Name</th>
1/dist/js/bootstrap.bundle.min.js" <th scope="col">Salary</th>
integrity="sha384- <th scope="col">Bonus</th>
HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBN
S5n7C8IVInixGAoxmnlMuBnhbgrkm" <th scope="col">Phone
Number</th>
crossorigin="anonymous"></script>
<th scope="col">Role</th>
<th scope="col">Department</th> <td>{{emp.phone}}</td>
<th scope="col">Location</th> <td>{{emp.role.name}}</td>
<th scope="col">Hiredate</th> <td>{{emp.dept.name}}</td>
<td>{{emp.dept.location}}</td>
<td>{{emp.hire_date}}</td>
</thead>
{% for emp in emps %} </tr>
<tbody>
</tbody>
<tr> {% endfor %}
<th scope="row">{{emp.id}}</th> </table>
<td>{{emp.first_name}}</td> </div>
<td>{{emp.last_name}}</td> </body>
<td>{{emp.salary}}</td> </html>
<td>{{emp.bonus}}</td>

Signature of Industrial Supervisor: ………………………

You might also like