Doctor model
class Doctor(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
qualifications = models.CharField(max_length=100)
expertise = models.CharField(max_length=100, default='Cardiac')
fee = models.IntegerField(default=500)
slots = models.IntegerField(default=0)
def incSlots(self):
self.slots = self.slots + 1
Appointment model
class Appointment(models.Model):
appointment_id = models.AutoField(primary_key=True)
patient = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
blood_pressure = models.CharField(max_length=10)
BMI = models.CharField(max_length=10)
blood_sugar = models.CharField(max_length=10)
HB = models.CharField(max_length=10)
platelets = models.CharField(max_length=10)
date = models.CharField(max_length=30)
time = models.CharField(max_length=30)
detail = models.TextField()
doc = models.OneToOneField(Doctor, on_delete=models.CASCADE)
Appointment view
def appointment(request):
docname = request.POST.get('doc_name')
if request.method == 'POST':
form = AppointmentForm(request.POST)
if form.is_valid():
form.doc.incSlots()
form.save()
return redirect('success')
else:
print(form.errors)
form = AppointmentForm(initial={"patient":request.user, "doc_name": docname})
return render(request, 'appointment.html', {'form': form})
I want to increment "slot" field when booking an appointment, I have no idea how to do it, i am new to django, i'll appreciate any help Thank you.
Aucun commentaire:
Enregistrer un commentaire