3

I am struggling to make this work for 2 days.

I am trying to make a record without saving historical record with Django-Simple-History.

Here is the case. I have a model :

class Artikel(models.Model):
    treaty = models.ForeignKey(Treaty)
    parent = models.ForeignKey(Heading, null=True, blank=True)
    artikel_type = models.CharField(max_length=255, null=False, blank=False,   choices=ARTIKEL_TYPE_CHOICES)
    title = models.CharField(max_length=255, null=True, blank=True)
    history = HistoricalRecords()

and here is my save() method

def save(self):
    self.save_without_historical_record()

Am I missing something crucial? Because I am getting this error:

AttributeError at /admin/treaties/artikel/329/
 skip_history_when_saving

1 Answer 1

0

Had the same error as you. The saved method was called recursively, so I added additional condition to the save method. Now my save method looks like this

def save(self, *args, **kwargs):
    if not hasattr(self, 'skip_history_when_saving'):
        return self.save_without_historical_record(*args, **kwargs)
    return super(Artikel, self).save(*args, **kwargs)

Hope this works for you also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.