Django Signals: The QuerySet value for an exact lookup must be limited to one result using slicing
i have this code in my models.py (post_save)
class StudentsEnrolledSubject(models.Model):
Students_Enrollment_Records = models.ForeignKey(StudentsEnrollmentRecord, related_name='+',
on_delete=models.CASCADE, null=True)
Subject_Section_Teacher = models.ForeignKey(SubjectSectionTeacher, related_name='+', on_delete=models.CASCADE,
null=True,blank=True)
@receiver(post_save, sender=StudentsEnrollmentRecord)
def create(sender, instance, created, *args, **kwargs):
teachers = SubjectSectionTeacher.objects.filter(Sections=instance.Section,Education_Levels=instance.Education_Levels,Courses=instance.Courses)
for each in teachers:
if created and teachers.exists():
StudentsEnrolledSubject.objects.update_or_create(
pk=
each.id,
Students_Enrollment_Records=instance,
Subject_Section_Teacher=teachers.all()
)
class StudentsEnrollmentRecord(models.Model):
Student_Users = models.ForeignKey(StudentProfile, related_name='students', on_delete=models.CASCADE, null=True)
class SubjectSectionTeacher(models.Model):
Education_Levels = models.ForeignKey(EducationLevel, related_name='+', on_delete=models.CASCADE, blank=True)
Courses = models.ForeignKey(Course, related_name='+', on_delete=models.CASCADE, null=True, blank=True)
Sections = models.ForeignKey(Section, related_name='+', on_delete=models.CASCADE, null=True)
Subjects = models.ForeignKey(Subject, related_name='+', on_delete=models.CASCADE, null=True)
Employee_Users = models.ForeignKey(EmployeeUser, related_name='+', on_delete=models.CASCADE, null=True)
when I used the **Subject_Section_Teacher=teachers.first()** i received no error but that is not what i want result, then i decide to change it to this **Subject_Section_Teacher=teachers.all()**