Take the 2-minute tour ×

I want to allow the user to provide his availability for any of three timeslots on any of the 7 days of the week.

The brute-force way to do this would be to simply provide 21 checkboxes, so

MONDAY_AM = models.BooleanField()
MONDAY_NOON = models.BooleanField()
SUNDAY_PM = models.BooleanField()

However this seems silly. What if I want to recall all the mondays, or all the evenings? It just doesn't seem like it would scale well.

I would like a more sophisticated approach, ideally one that would allow me to register these models to Django's admin so that I could see each user's availability in a table form, such as

     |Mo Tu We Th Fr Sa Su
AM   | x  x
NOON |       x  x     x  x
PM   |       x        x  x

Any help would be much appreciated (and yes, thus far Doodle vastly outstrips the functionality of my thing, but 1. it's a learning project, 2. i plan to take it in a different direction)

edit: BTW, coming from Python and Qt and whatnot, my initial approach was nested for loops and dictionary, but South and Django seemed not to like that. I need to think more "database-like", so don't be afraid to submit something that's almost trivial. It's probably what I need, really.

share|improve this question
add comment

1 Answer

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):
        (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.

share|improve this answer
why do you have an "AutoField" line? the rest is excellent and straightforward. Thanks! –  RodericDay Nov 23 '12 at 17:57
Yes you can exclude auto field line. Thanks –  Aamir Adnan Nov 23 '12 at 20:01
add comment

Your Answer


