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()**


On Tue, Nov 5, 2019 at 1:21 PM Motaz Hejaze <trapper...@gmail.com> wrote:

> If you need any help please let me know
>
> My skype
>
> m3tz-hjze
>
> On Mon, 4 Nov 2019, 4:44 pm Laura Pérez, <lpver...@gmail.com> wrote:
>
>> Thanks!
>>
>> Em seg, 4 de nov de 2019 às 09:59, Paras Jain <parasjain...@gmail.com>
>> escreveu:
>>
>>> Hi,
>>> just follow this video u will easily know how to make api very easily
>>> link - https://www.youtube.com/watch?v=263xt_4mBNc
>>> Thnks
>>>
>>> On Mon, Nov 4, 2019 at 6:17 PM Laura Pérez <lpver...@gmail.com> wrote:
>>>
>>>> Hi!
>>>> I have the task to develop a rest api in python, Can anybody advice me
>>>> on a nice tutorial to use djangorest framework ?
>>>>
>>>> Best!
>>>>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to django-users+unsubscr...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/CAF_dEnq90i0zxOgwGANXaFk_eEWJn4N6d544U1r-qwPS1M92jg%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAF_dEnq90i0zxOgwGANXaFk_eEWJn4N6d544U1r-qwPS1M92jg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAMtmBS_11roQXUzFHb%3Dvus1MnaqqjQV8CmZS5jLrXZDZKvnNAw%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAMtmBS_11roQXUzFHb%3Dvus1MnaqqjQV8CmZS5jLrXZDZKvnNAw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> --
>> Laura Pérez Vera
>> (+53) 53440970 - lpver...@gmail.com
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAF_dEnock0uZ%2B9Vrg6Kyf%2B7z1NVzTQpBA55R4k27CdJ2OHGWtg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAF_dEnock0uZ%2B9Vrg6Kyf%2B7z1NVzTQpBA55R4k27CdJ2OHGWtg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHV4E-cSxYkj0rMWau%3DzMJDBBoxzX7H8M7J5dmRKoHEYxPwiiQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAHV4E-cSxYkj0rMWau%3DzMJDBBoxzX7H8M7J5dmRKoHEYxPwiiQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOgSYSDLvabZbSB62A_Zfx_jYH9w4A68Dme7kqm1nsn0qX_oDw%40mail.gmail.com.

Reply via email to