I have a custom .save method on my model. The model has a start_date and a last_edited value. If the difference between these values is more than 14 days, it should copy/clone itself on save (instead of saving).
You probably already see the problem: infinite recursion. If the clone saves itself, the values will still differ 14 days and the whole copy process will start anew.
Therefore I want to to pass these copies a 'copy' argument in their .save parameter, in order to prevent them from triggering the copy process themselves.
To this end I've written the following code:
def save(self, *args, **kwargs):
#check if a submission is older than the 'create a new one' threshold
#Create a new one if that is the case
delta = self.last_edited - self.start_date
print(args)
print(kwargs)
if 'copy' in kwargs or 'copy' not in args:
print('cloning!')
if delta.days >= 14:
clone = self
clone.pk = None
clone.save('copy')
super(AssessmentSubmission, self).save(*args, **kwargs)
However, for some reason clone.save(copy) does not pass the 'copy' variable to the .save method. I even added some print statements to print all args and kwarg arguments, but both return empty lists/ dicts.
Does anyone know what I am doing wrong?