Made filters using django and sql.

Changed schedule html file accordingly
Co-authored-by: 's avatarChristine <cdeeerrr@users.noreply.github.com>
Co-authored-by: 's avatarpinkboheme <pinkboheme@users.noreply.github.com>
parent 305f54f6
......@@ -8,7 +8,6 @@
{% block content %}
<h1 class='view-title'>Schedule </h1>
<table id="scheduling-table">
<tr>
<th>Week</th>
......@@ -16,13 +15,15 @@
<th>Role</th>
<th>Day-Mgr</th>
</tr>
{% for m in manager%}
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
<td>Alfreds Futterkiste</td>
<td> {{m.role_date}}</td>
<td> {{m.employee.employee_name}} </td>
<td> {{m.role_description}} </td>
<td> {{m.is_manager}} </td>
</tr>
{% endfor %}
</table>
{% endblock %}
......@@ -36,6 +36,11 @@ class EmployeeRole(models.Model):
role_description = models.CharField(max_length=20, choices=ROLES)
is_manager = models.CharField(max_length=1, choices=IS_MANAGER)
def employeename(self):
return self.employee.employee_name
class Meta:
managed = False
db_table = 'employeerole'
......@@ -23,48 +23,54 @@ def inventory(request):
def schedule(request):
# filter employees and roles by date in order
# 😁 filter employees and roles by date in order
for row in EmployeeRole.objects.raw('''SELECT * FROM employeerole RIGHT JOIN employee ON (employeerole.employee_id=employee.employee_id)
ORDER BY role_date ASC'''):
print(row.employee_name, row.role_description, row.role_date)
# filter employees and roles in alphabetical order
# 😁 filter employees and roles in alphabetical order
for row in EmployeeRole.objects.raw('''SELECT * FROM employeerole RIGHT JOIN employee ON (employeerole.employee_id=employee.employee_id)
ORDER BY employee_name, role_date ASC'''):
print(row.employee_name, row.role_description, row.role_date)
# filter employees by roles
# 😁 filter employees by roles
for row in EmployeeRole.objects.raw('''SELECT role_id,employee_name, role_date FROM employeerole RIGHT JOIN employee ON (employeerole.employee_id=employee.employee_id)
WHERE role_description ILIKE 'cashier' '''):
print(row.employee_name, row.role_description, row.role_date, '- filter by roles')
# filter employees by manager for the day
# 😁 filter employees by manager for the day
for row in EmployeeRole.objects.raw('''SELECT role_id,employee_name, role_date FROM employeerole RIGHT JOIN employee ON (employeerole.employee_id=employee.employee_id)
WHERE is_manager ILIKE 'Y' '''):
print(row.employee_name, row.role_description, row.role_date, '- manager for the day')
# filter employees by week
# 😁 filter employees by week
for row in EmployeeRole.objects.raw('''SELECT * FROM employeerole RIGHT JOIN employee ON (employeerole.employee_id=employee.employee_id)
WHERE role_date <= '2025-09-06' AND role_date >= '2025-09-01' ORDER BY role_date '''):
pass
# employeeroles = {}
# for role in EmployeeRole.objects.raw('''SELECT * FROM employeerole'''):
# print dates when they're managers
# if role.is_manager == 'Y':
# print(role.employee.employee_name, 'is a manager on', role.role_date)
#
# employeename = role.employee.employee_name
# employeerole = role.role_description
# day_mgr = []
# if role.employee.employee_name not in employeeroles:
# employeeroles[employeename] = employeerole
#
# print(employeeroles)
return render(request, "blizzardblast/templates/schedule.html")
# 1: FILTER EMPLOYEES BY MANAGER FOR THE DAY
ismanager_query = EmployeeRole.objects.all().filter(is_manager='Y')
# 2: FILTER EMPLOYEES AND ROLES IN ALPHABETICAL ORDER
employee_role_order_query = EmployeeRole.objects.all().order_by('role_description')
# 3 : FILTER BY WEEK
week_query1 = EmployeeRole.objects.all().filter(role_date__range=["2025-09-01", "2025-09-06"]).order_by('role_date')
week_query2 = EmployeeRole.objects.all().filter(role_date__range=["2025-09-08", "2025-09-13"]).order_by('role_date')
# 4: FILTER EMPLOYEES BY ROLES
role_query1 = EmployeeRole.objects.all().filter(role_description='Cashier')
role_query2 = EmployeeRole.objects.all().filter(role_description='Preparation')
role_query3 = EmployeeRole.objects.all().filter(role_description='Cleaning')
# 5: FILTER EMPLOYEES AND ROLES BY DATE IN ORDER
date_order_query = EmployeeRole.objects.all().order_by('role_date')
return render(request, "blizzardblast/templates/schedule.html", {
'manager': employee_role_order_query
}
)
def report(request):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment