[Solved]-Django – Objects for business hours

19πŸ‘

βœ…

From @lyapun suggestion, an acceptable solution for me would be:

WEEKDAYS = [
  (1, _("Monday")),
  (2, _("Tuesday")),
  (3, _("Wednesday")),
  (4, _("Thursday")),
  (5, _("Friday")),
  (6, _("Saturday")),
  (7, _("Sunday")),
]


class Company(models.Model):
    name = models.CharField(
        max_length=100
    )
    logo = models.FileField(
        upload_to='company_logos'
    )



class OpeningHours(models.Model):
    store = models.ForeignKey(
        Company
    )
    weekday = models.IntegerField(
        choices=WEEKDAYS,
        unique=True
    )
    from_hour = models.TimeField()
    to_hour = models.TimeField()

Leave a comment