0

I want to build an app that make easier Teacher and Student to have an appointment.

Teacher have to submit their availabilities. For example, make them allow to tell student I'm available for appointment such date at such hour.

Student can see all their availabilities and then can choice the appointment.

Here is my models.py :

class Appointment(models.Model):

    class Meta:
        unique_together = ('teacher', 'date', 'timeslot')

    TIMESLOT_LIST = (
        (0, '09:00 – 10:00'),
        (1, '10:00 – 11:00'),
        (2, '11:00 – 12:00'),
        (3, '12:00 – 13:00'),
        (4, '13:00 – 14:00'),
        (5, '14:00 – 15:00'),
        (6, '15:00 – 16:00'),
        (7, '16:00 – 17:00'),
        (8, '17:00 – 18:00'),
        (9, '18:00 – 19:00'),
        (10, '19:00 – 20:00'),
    )
    student = models.OneToOneField('Student', null=True, on_delete=models.CASCADE)
    teacher = models.OneToOneField('Staff', null=True, on_delete=models.CASCADE)
    date = models.DateField()
    timeslot = models.IntegerField(choices=TIMESLOT_LIST)

    def __str__(self):
        return '{} {} {}. Etudiant : {}'.format(self.date, self.time, self.doctor, self.patient_name)

    @property
    def time(self):
        return self.TIMESLOT_LIST[self.timeslot][1]

    is_completed = models.BooleanField(default=False)
    is_confirmed = models.BooleanField(default=False)

So when the teacher will fill their availabilities, this will create many appointment objects and student have to choice one of them. I was asking myself there is an other possibility to not create as much appointment objects ?

anthonya
  • 565
  • 2
  • 6
  • 15
  • see this post: https://stackoverflow.com/questions/6928692/how-to-express-a-one-to-many-relationship-in-django – LucasBorges-Santos Aug 04 '21 at 17:50
  • You mean having an Appointment model with a foreign key for the Student and a foreign key for the Teacher ? Then, how can I handle the availabilities ? – anthonya Aug 10 '21 at 16:46

0 Answers0