1👍
✅
Maybe something like this could work:
class Appointment(models.Model):
day = models.DateField()
available = models.BooleanField(default=True)
classroom = models.ManyToManyField(Classroom, related_name='appointments')
EDIT:
Availability should be rather placed in the middle table between Classroom and Appointment and the ManyToManyField should have through=tablename
where tablename is the name of this table.
EDIT:
Actually I wanted to have a supper, but this question is now more important than my appetite 🙂
class Classroom(models.Model):
name = CharField(max_length=128)
class WeekendDay(models.MOdel): # this was before Appointment
day = models.DateField()
classroom = models.ManyToManyField(Classroom, through="Appointment")
class Appointment(models.Model)
available = models.BooleanField(default=True)
weekend_day = models.ForeignKey(WeekendDay, related_name='appointments_per_day')
classroom = models.ForeignKey(Classroom, related_name='appointments_per_classroom')
I think something like this should work, if you have many classrooms, which are available on many days. Through the field available
you can see or set the availability. If a classroom is booked let’s say on next Saturday, then its value should be set to False
. This should be the basic skeleton, you can extend the models according to your needs.
Source:stackexchange.com