I have the following model
, which when saved calculates hash_id
field based on the pk
:
class MyTable(models.Model):
something = models.CharField(max_length=255)
reported = models.IntegerField(default=0, blank=True)
hash_id = models.CharField(max_length=32, db_index=True, unique=True, blank=True)
def save(self, *a, **kw):
super().save(*a, **kw)
self.hash_id = hash_fn(self.pk)
super().save(*a, **kw)
In one of my views
I have the following lines, which are supposed to increment reported
field by 1, however reported
is incremented by 2, because of the overridden save
method:
my_table_ins.reported = F('reported') + 1
my_table_ins.save()
Ideally I would like something among the lines:
def save(self, *a, **kw):
super().save(*a, exclude=['reported'], **kw)
self.hash_id = hash_fn(self.pk)
super().save(*a, **kw)