1

I am firing a signal which has 3 different receivers. What I want to do is to update a table Student using the signal update_student and later on I want to update his enrollment in update_student_enrollment.

I want to update Enrollment after the Student has been updated. But my update enrollment receiver is triggering before the student is updated.

Sending the signal.

Signal.send("student_updated", student_id=1, active=active)

Receiver 1

@receiver(student_updated)
def update_student(sender, **kwargs):
    Student.objects.update(active=0) # I am setting the student activation to false. For simplicity I am not mentioning the logic which is setting the student to inactive.    
    print("Student Updated!")

Receiver 2

@receiver(student_updated)
def update_student_enrollment(sender, **kwargs):
    student=Student.objects.filter(student_id=1)
    if student.active=0:
        StudentEnrollment.objects.filter(student_id=1).update(active=0)

Somehow my Receiver 2 is firing before the Receiver 1.

Ariel
  • 3,383
  • 4
  • 43
  • 58
A.J.
  • 8,557
  • 11
  • 61
  • 89
  • Possible duplicate of [what's the order of post\_save receiver in django?](http://stackoverflow.com/questions/20990146/whats-the-order-of-post-save-receiver-in-django) – e4c5 May 19 '17 at 07:22

1 Answers1

1

It's not possible to explicitly specify the ordering of signals in Django.

The best way you can handle this is by having the Receiver 1 signal send a signal itself on which you can let Receiver 2 listen.

MichielB
  • 4,181
  • 1
  • 30
  • 39