I'm trying to update some other items of the same Model after creating new item and based on id of newly created item. That is why I have to do it after save. But I'm getting following error:
maximum recursion depth exceeded
The item object seems to be valid and the for loop itself is not recursive and iterates through the item objects normally. Introducing save() raises the error. Obviuosly I don't seem to fully understand the inner workings of save() method. Appreciate any help.
The code:
class SimCardInTracker(models.Model):
tracker = models.ForeignKey(Tracker)
simcard = models.ForeignKey(SimCard)
start = models.DateTimeField(auto_now_add=True, unique=True)
end = models.DateTimeField(null=True, blank=True)
def __unicode__(self):
return self.tracker.serial_no
def save(self, *args, **kwargs):
super(SimCardInTracker, self).save(*args, **kwargs)
prev_items = SimCardInTracker.objects.exclude(id = self.id).filter(tracker__id = self.tracker.id)
for item in prev_items:
item.end = datetime.datetime.now()
item.save()