I am quite new to Django and I'm trying to build a web application where some users will be able to input their available weekly schedule and also show at what times of a day they are available. The picture below(this is just front-end part) shows something similar to what I'm trying to build. What type of Model field do I use to store this type of information inside of a Model class?
Asked
Active
Viewed 302 times
2 Answers
2
I would use a ManyToMany field which links to a Shift
table.
class Shift(models.Model):
# Day of week
day = models.CharField()
# Morning, afternoon, evening
time = models.CharField()
class UserProfile(models.Model):
...
availability = models.ManyToManyField(Shift)
The Django docs have a handy guide on using ManyToManyFields. https://docs.djangoproject.com/en/4.1/topics/db/examples/many_to_many/

James Dernie
- 158
- 8
0
Now that I look at it I can try to create many MultiSelect fields for each of the days(Sunday,Monday,Tuesday,...Saturday) and each of them will have 3 choices(Morning, Afternoon, Evening). This way you wouldn't need to prepopulate the database(before using the database) with all different options(Sunday Morning,Monday Evening etc.) However, I might run into the trouble of having redundancy in my table in the long run.

Ixion Chowdhury
- 140
- 11