[Answer]-Doodle-like functionality in a Django model?

1👍

In past I was also required this feature. In which Teacher has to define its availability timing in any of the day, so I came up with this model:

class Availability(models.Model):
    WEEKDAY_CHOICES = (
        (0, 'Monday'),
        (1, 'Tuesday'),
        (2, 'Wednesday'),
        (3, 'Thursday'),
        (4, 'Friday'),
        (5, 'Saturday'),
        (6, 'Sunday'),
    )
    id = models.AutoField(primary_key=True)
    teacher = models.ForeignKey(Teacher)
    weekday = models.PositiveSmallIntegerField(choices=WEEKDAY_CHOICES)
    start_time = models.TimeField(null=True, blank=True)
    end_time = models.TimeField(null=True, blank=True)

    class Meta:
        db_table = 'availability'
        unique_together = ("teacher", "weekday")

I hope this will help you to get somewhere.

Leave a comment