I want to save two objects, one of them is related through ForeignKey('self').
I want to check if save()
method was called through django admin or as recursive method from the save()
itself. Since I want to save two instances of the object and not infinite amount of them.
The model:
prev_work = models.ForeignKey('self', on_delete=models.CASCADE,
editable=False, null=True, blank=True)
Code for saving:
prev_work = Work(chapter=self.chapter, job=self.job, prev_work=self)
prev_work.save()
I'm expecting to save two objects but I don't know how to stop the program from calling save each time it comes to the end of the method. I done it through other means but still I would like to know how can I check if method was called from django admin. Thanks!