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 @@ ...@@ -8,7 +8,6 @@
{% block content %} {% block content %}
<h1 class='view-title'>Schedule </h1> <h1 class='view-title'>Schedule </h1>
<table id="scheduling-table"> <table id="scheduling-table">
<tr> <tr>
<th>Week</th> <th>Week</th>
...@@ -16,13 +15,15 @@ ...@@ -16,13 +15,15 @@
<th>Role</th> <th>Role</th>
<th>Day-Mgr</th> <th>Day-Mgr</th>
</tr> </tr>
{% for m in manager%}
<tr> <tr>
<td>Alfreds Futterkiste</td> <td> {{m.role_date}}</td>
<td>Maria Anders</td> <td> {{m.employee.employee_name}} </td>
<td>Germany</td> <td> {{m.role_description}} </td>
<td>Alfreds Futterkiste</td> <td> {{m.is_manager}} </td>
</tr> </tr>
{% endfor %}
</table> </table>
{% endblock %} {% endblock %}
...@@ -36,6 +36,11 @@ class EmployeeRole(models.Model): ...@@ -36,6 +36,11 @@ class EmployeeRole(models.Model):
role_description = models.CharField(max_length=20, choices=ROLES) role_description = models.CharField(max_length=20, choices=ROLES)
is_manager = models.CharField(max_length=1, choices=IS_MANAGER) is_manager = models.CharField(max_length=1, choices=IS_MANAGER)
def employeename(self):
return self.employee.employee_name
class Meta: class Meta:
managed = False managed = False
db_table = 'employeerole' db_table = 'employeerole'
...@@ -23,48 +23,54 @@ def inventory(request): ...@@ -23,48 +23,54 @@ def inventory(request):
def schedule(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) for row in EmployeeRole.objects.raw('''SELECT * FROM employeerole RIGHT JOIN employee ON (employeerole.employee_id=employee.employee_id)
ORDER BY role_date ASC'''): ORDER BY role_date ASC'''):
print(row.employee_name, row.role_description, row.role_date) 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) 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'''): ORDER BY employee_name, role_date ASC'''):
print(row.employee_name, row.role_description, row.role_date) 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) 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' '''): WHERE role_description ILIKE 'cashier' '''):
print(row.employee_name, row.role_description, row.role_date, '- filter by roles') 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) 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' '''): WHERE is_manager ILIKE 'Y' '''):
print(row.employee_name, row.role_description, row.role_date, '- manager for the day') 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) 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 '''): WHERE role_date <= '2025-09-06' AND role_date >= '2025-09-01' ORDER BY role_date '''):
pass pass
# employeeroles = {} # 1: FILTER EMPLOYEES BY MANAGER FOR THE DAY
# for role in EmployeeRole.objects.raw('''SELECT * FROM employeerole'''): ismanager_query = EmployeeRole.objects.all().filter(is_manager='Y')
# print dates when they're managers # 2: FILTER EMPLOYEES AND ROLES IN ALPHABETICAL ORDER
# if role.is_manager == 'Y': employee_role_order_query = EmployeeRole.objects.all().order_by('role_description')
# print(role.employee.employee_name, 'is a manager on', role.role_date)
# # 3 : FILTER BY WEEK
# employeename = role.employee.employee_name week_query1 = EmployeeRole.objects.all().filter(role_date__range=["2025-09-01", "2025-09-06"]).order_by('role_date')
# employeerole = role.role_description week_query2 = EmployeeRole.objects.all().filter(role_date__range=["2025-09-08", "2025-09-13"]).order_by('role_date')
# day_mgr = []
# if role.employee.employee_name not in employeeroles: # 4: FILTER EMPLOYEES BY ROLES
# employeeroles[employeename] = employeerole role_query1 = EmployeeRole.objects.all().filter(role_description='Cashier')
# role_query2 = EmployeeRole.objects.all().filter(role_description='Preparation')
# print(employeeroles) role_query3 = EmployeeRole.objects.all().filter(role_description='Cleaning')
return render(request, "blizzardblast/templates/schedule.html") # 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): 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