Я настраиваю приложение django, в котором я использую поле один в один, когда я добавляю студенту detial из бэкэнда, он работает хорошо, но формирует форму внешнего интерфейса и выдает следующую ошибку: «IntegrityError at / prog
УНИКАЛЬНОЕ ограничение не выполнено: grading_program_of_study.student_id
«
//////////////my view code////////////////
def prog(request):
if request.method == 'POST':
if request.POST['program_name'] and request.POST['date_of_entry'] and request.POST['faculty']and request.POST['department'] and request.POST['program_type'] and request.POST['date_of_complition']:
Program_of_study = program_of_study()
Program_of_study.program_name = request.POST['program_name']
Program_of_study.date_of_entry = request.POST['date_of_entry']
Program_of_study.faculty = request.POST['faculty']
Program_of_study.department = request.POST['department']
Program_of_study.department = request.POST['program_type']
Program_of_study.date_of_complition = request.POST['date_of_complition']
Program_of_study.save()
return redirect('home',{'sucess':'Program added sucessfully'})
else:
return render(request,'grading/home.html')
else:
return render(request,'grading/home.html')
########### my model code################################
class program_of_study(models.Model):
student = models.OneToOneField(student_details, on_delete=models.CASCADE,default = 1)
program_name = models.CharField(max_length=50)
date_of_entry = models.DateField()
faculty = models.CharField(max_length=50)
department = models.CharField(max_length=50)
program_type = models.CharField(max_length=50)
date_of_complition = models.DateField()
def __str__(self):
return self.program_name