django simple history customising Base Class

64 Views Asked by At

I would like to start tracking changes made to a model using django-simple-history. I have a big model but would only need to track the history of a couple fields. I could use the exclude_fields parameter, but as the model gets larger, I do not want to manually keep on adding items that need to be excluded. I would like the basemodel history returns to be only the selected fields (bonus if history is only saved when one of these two fields changes, but not required).

I have the following big model where I need to start tracking 2 fields:

class Organisation(models.Model):
       .... lots of other fields
       balance = models.DecimalField(
        max_digits=15, decimal_places=2, default=Decimal('0.00'))
       costs = models.DecimalField(
        max_digits=15, decimal_places=2, default=Decimal('0.00'))
       history = HistoricalRecords() # only want to save history on fields balance and costs

# basemodel that needs to be saved by history
class OrganisationHistoryTrackedFields(models.Model):
       balance = models.DecimalField(
        max_digits=15, decimal_places=2, default=Decimal('0.00'))
       costs = models.DecimalField(
        max_digits=15, decimal_places=2, default=Decimal('0.00'))
       
0

There are 0 best solutions below