如何在django获得医生预约时间
我有两个模特,时间安排和约会。 我如何获得医生在不同时段15分钟的持续时间。我在这方面越来越空白了 模型如何在django获得医生预约时间,django,django-rest-framework,Django,Django Rest Framework,我有两个模特,时间安排和约会。 我如何获得医生在不同时段15分钟的持续时间。我在这方面越来越空白了 模型 class Schedule(models.Model): doctor=models.ForeignKey(Doctor) open=models.TimeField() close=models.TimeField() class Appointment(models.Model): patient=models.ForeignKey(Patient)
class Schedule(models.Model):
doctor=models.ForeignKey(Doctor)
open=models.TimeField()
close=models.TimeField()
class Appointment(models.Model):
patient=models.ForeignKey(Patient)
doctor=models.ForeignKey(Doctor)
date=models.DateField()
time_slot=models.TimeField()
基于我们在评论中的讨论,我将不向您提供确切的代码(因为您还没有做任何事情)。但我会向你们解释你们可以采取的不同方法(我现在可以想)
在评论中询问详细信息,我将相应地更新答案。以下是该问题的解决方案
from django.db import models
class Appointment(models.Model):
"""Contains info about appointment"""
class Meta:
unique_together = ('doctor', 'date', 'timeslot')
TIMESLOT_LIST = (
(0, '09:00 – 09:30'),
(1, '10:00 – 10:30'),
(2, '11:00 – 11:30'),
(3, '12:00 – 12:30'),
(4, '13:00 – 13:30'),
(5, '14:00 – 14:30'),
(6, '15:00 – 15:30'),
(7, '16:00 – 16:30'),
(8, '17:00 – 17:30'),
)
doctor = models.ForeignKey('Doctor',on_delete = models.CASCADE)
date = models.DateField(help_text="YYYY-MM-DD")
timeslot = models.IntegerField(choices=TIMESLOT_LIST)
patient_name = models.CharField(max_length=60)
def __str__(self):
return '{} {} {}. Patient: {}'.format(self.date, self.time, self.doctor, self.patient_name)
@property
def time(self):
return self.TIMESLOT_LIST[self.timeslot][1]
class Doctor(models.Model):
"""Stores info about doctor"""
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
middle_name = models.CharField(max_length=20)
specialty = models.CharField(max_length=20)
def __str__(self):
return '{} {}'.format(self.specialty, self.short_name)
@property
def short_name(self):
return '{} {}.{}.'.format(self.last_name.title(), self.first_name[0].upper(), self.middle_name[0].upper())
要获得完整的源代码,请点击!您能清楚地解释问题吗?假设有一位x医生的在线会话从上午10点开始,到晚上6点结束,在这段时间内,10到6次医生的每次会话都有15分钟。那么我如何向患者显示这些时间段,患者如何预订这些时间段插槽。如果一个插槽被预订了,没有人可以预订这个插槽。到目前为止,你写了什么代码?你能展示一些示例吗?我到目前为止还没有做任何事情,但我只能预订没有时间插槽的约会,这就是我变得空白的地方??你能告诉我应该如何处理吗谢谢你的指导,我正在处理这个问题,谢谢你的指导,我会的向你展示我的代码。如果答案解决了你的问题,请接受它并投票帮助他人。朋友,我也一定会帮助他人