[Fixed]-Dictionary In Django Model

1👍

I would suggest structuring your database in a more normalized fashion so that you can more easily query it and the table won’t be so unwieldy. An example might be:

class Timesheet(models.Model):
    employee = models.CharField()
    company = models.CharField()
    time_in = models.DateTimeField()
    time_out = models.DateTimeField()

From this, you can save a point of data every time an employee checks in or checks out. You can also calculate their hours, etc. I suppose you may also want to save additional fields to suit your purposes, but the above should give you a good starting point.

If you wanted to get a query for John on Monday, you would use the WEEKDAY() function, for example:

SELECT time_in, time_out FROM Timesheet WHERE employee = "John" AND WEEKDAY(time_in) = 0

If your employees are from all over the world, you might want to store a tz_offset column in the database and keep all dates in UTC. If all the employees are working in the same timezone, then it’s simpler and you can just store the time in the local timezone.

Leave a comment