javascript - 预约功能
问题描述
我有一个 Django 项目,它在 model.py 文件中包含两个类,一个是诊所(其中有一个联系号码作为字段),另一个是病人。我已经将所有诊所都呈现在卡片中,每张卡片都有一个按钮预约。
这是我的model.py:
class Clinic(models.Model):
clinic_name = models.CharField(max_length=200, blank=True, verbose_name='Name')
poster = models.ImageField(blank=True, null=True, upload_to='uploads/%Y/%m/%d', verbose_name='Picture')
address = models.TextField(max_length=500, blank= True)
contact_no = models.CharField(max_length=12, blank=True, verbose_name='Mobile')
def __str__(self):
return self.clinic_name
class Patient(models.Model):
clinic = models.ForeignKey(Clinic, on_delete=CASCADE)
patient_name = models.CharField(max_length=200, blank=True)
contact_no = models.CharField(max_length=12, blank=True)
appointment_time = models.DateTimeField(auto_now=True)
def __str__(self):
return self.patient_name
现在我想要的是,当一个在这种情况下有耐心的真实用户点击预约时,应该在诊所电话号码上发送一条消息,说这个人已经在这个日期与你预约了。
这怎么能实现???请指导我。
解决方案
楷模:
from django import models
class Appointment(models.Model):
clinic = models.ForeignKey(Clinic, on_delete=models.CASCADE, related_name='appointments')
patient = models.ForeignKey(Patient, on_delete=models.CASCADE, related_name='appointments')
time = models.DateTimeField()
def __str__(self):
return f'{self.clinic} - {self.patient} - {self.time}'
形式:
from django import forms
from .models import Appointment
class AppointmentForm(forms.ModelForm):
class Meta:
model = Appointment
fields = ('clinic', 'time',)
网址:
from .views import book_appointment_view
app_name = '<appname>'
path('book-appointment/', book_appointment_view, name='book-appointment')
意见:
from django.urls import redirect
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseBadRequest
@login_required
def book_appointment_view(request):
if request.method == 'POST':
form = AppointmentForm(request.POST or None)
user = request.user
if form.is_valid():
form.save(commit=False)
form.instance.patient = user
form.save()
messages.success(request, f'Appointment booked {form.instance.patient.patient_name} !')
return redirect('/')
else:
HttpResponseBadRequest('You can not do that')
html:
<form method="post" action="{% url '<appname>:book-appointment' %}">
{% csrf_token %}
{{ form }}
<button type="submit">Send</button>
</form>
至于短信,请查看django-twillio的短信。我听说过好东西。
推荐阅读
- php - 如果消息文本上有句点,PHP Sendmail 会失败
- discord - 我在尝试制作我的不和谐机器人时遇到错误
- apache-spark - 事件中心流式处理使用 DataBricks 提高处理速度
- r - 在跨函数的 .names 参数中使用函数
- javascript - 在表单中单击按钮时创建文本输入
- python - 如何将整数转换为数字
- ruby - 如何使用 Chef 配方通过读取 Shell 脚本来设置环境变量?
- mysql - LOAD DATA LOCAL INFILE 的日期格式
- mongodb - AWS / VPC / MongoDB Atlas - 一个分片不工作
- python - 通过 to_hdf 将 pandas 数据框对象写入 hdf5 会创建axis0、axis1、block0_items 和block0_values,但为什么呢?