For simplicity, there is a set of models:
class A(models.Model): name = models.CharField(max_length=255) class B(models.Model): name = models.CharField(max_length=255) owner = models.ForeignKey(A, on_delete=models.CASCADE, null=False) def foo(): do something
The number of instances of B belonging to A is not known in advance. The number of instances of B is determined by the user at the time of creating a new instance of A. Moreover, he can create an instance of A without creating a single instance of B (empty set).
Challenge: I need to run foo after saving a new instance of A. This function should handle both the fields of the new instance of A and fields of B (back relation).
Yes, I have set the receiver to post_save signal model A. But here’s the problem, at the moment when A is already saved (post_save), instances of B have not yet been saved (pre_save), and the values of the corresponding fields have not been determined. In other words, I cannot get raw B values in receiver A.
Any ideas? Am I doing something wrong?