'How to delete multiple records from different classes in django?

It seems that whenever I run it and delete records I get server error (500) but it deletes the the data of class Bscs1_1 but for the rest of the classes it does not delete, I'm knew in web development so I don't know what's causing the problem please help...

these are my classes in models.py where I would like to delete records from:

class Bscs1_1(models.Model):

idNumber = models.CharField(max_length=15)
CC100 = models.FloatField()
CC101 = models.FloatField()
resultCS11 = models.IntegerField()
courseCS1 = models.TextField()

class Cs(models.Model): cs_count = models.TextField()

class Retention_cs1(models.Model): retention_count = models.TextField()

And this is how I add records from views.py:

def resultCS1_1(request):

CC100 = request.POST['CC100']
CC101 = request.POST['CC101']
        
prediction = model1.predict([[CC100,CC101]])
studentID = request.POST['studentID']

student1 = Bscs1_1()
student1.idNumber = studentID
student1.resultCS11 = prediction
student1.CC100=CC100
student1.CC101=CC101
student1.save()

courseCS1 = Cs(cs_count='BSCS1')
courseCS1.save()

retention = Retention_cs1()
if prediction == 0:
    retention.retention_count = 'NEGATIVE'
else:
    retention.retention_count = 'POSITIVE'
retention.save()

return render(request, "rCS1_1.html" , {'student1': student1} )

This is how I delete records from all those classes all in one click of a button:

def deleteCS12(request, student_id):

stud = Bscs1_1.objects.get(pk=student_id) stud.delete()

csCount = Cs.objects.get(pk=student_id) csCount.delete()

retention = Retention_cs1.objects.get(pk=student_id) retention.delete()

return redirect('tableCS12')



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source