Reputation: 5
Lets say, I want to track my workers attendence. There are 30 locations thoughout the country. There are 4000 workers in each sector and roughly 200 working days.
Every worker has separate profile page.
I'm using mysql database. What should I do? 1. Should I create a single table for a day?(30*200 tables for 200 days) 2. Should I create a single coulmn in a table for a day?(1 table per year and per location, 200 days in a table columns) So, how can I write the model for achieving this? What is the standard way and will be better in the long run.
I should mention the working days are not fixed so these would be dynamic like when I will enter the date it will create one table/column for me in the database.
Upvotes: 0
Views: 45
Reputation: 4208
It's kinda hard to get what you actually want but if i'm getting it correctly then here is my answer:
One table for your locations.
One table for your worker's profile.
One table for saving workers attendance.
If your working days need some details, let's say some sort of notes or etc, you can make a separate a table for working days.
Now you can save all the details about workers attendance in a single table and map it to other tables and filter through them as you wish.
Example:
Location fields:
Worker fields:
first_name
last_name
phone_number
...
Attendance fields:
worker (ForeignKey to worker table)
location (ForeignKey to location table)
date
notes
...
some filtering examples:
#Get all the workers for a location in a specific date)
Attendance.objects.filter(location=<SOME-LOCATIOn>, date=<SOME-DATE>
#Get all the details for a specific worker
Attendance.objects.filter(worker=<SOME-WORKER>)
Upvotes: 1