Sorry I am beginer in django try to make app for appointment for doctors and could not solved this problem
I can't add value in to Appoiment Db in to django app this is my models.py
from django.db import models
models.py_
class Doctors(models.Model):
doctor_name = models.CharField(max_length=80)
specialization_doctor = models.CharField(max_length=80)
def __str__(self):
return self.doctor_name
class Appoiment(models.Model):
doctor_name = models.ManyToManyField(Doctors)
date_appoiment = models.DateField()
time_appoiment = models.TimeField()
patient_name = models.CharField(max_length=80)
patient_phone = models.CharField(max_length=15)
reason_for_visit = models.TextField(max_length=400)
def __str__(self):
return self.patient_name
And this is my views.py I'm trying many ways but steal can't approch to solve it.
VIEWS.PY
from django.shortcuts import render
from .models import Doctors,Appoiment
from .forms import AppoimentForm
from django.http import HttpResponseRedirect
def main(request):
list_of_doctors = Doctors.objects.all().values('doctor_name')
list_of_doctors = [item['doctor_name']for item in list_of_doctors]
doctor_name=''
date_appoiment=''
time_appoiment=''
name=''
phone=''
reason=''
form = ''
patient=''
if request.method == 'POST':
doctor_name = request.POST.get('doctor_name')
date_appoiment = request.POST.get('date')
time_appoiment = request.POST.get('time')
name = request.POST.get('name')
phone = request.POST.get('phone')
reason = request.POST.get('reason')
# doctor = Doctors()
# The problem is here how to write right statement
#------->>
patient = Appoiment.objects.create(doctor_name=doctor_name,date_appoiment=date_appoiment,time_appoiment=time_appoiment,patient_name=name,patient_phone=phone,reason_for_visit=reason)
return render(request,'main.html',{'list_of_doctors':list_of_doctors,'patient':patient})```
Appoimentobject when a form is submitted, but you're encountering an issue with how to set thedoctor_namefield. Is it the issue?