I am using django-simple-history to track changes to some fields on my models.
My simplified model setup:
class Collection(models.Model):
description = models.TextField()
# ...
history = simple_history.HistoricalRecords()
class Item(models.Model):
content = models.TextField()
collection = models.ForeignKey(Collection, related_name="items", on_delete=models.CASCADE)
# ...
history = simple_history.HistoricalRecords()
Now ideally I would like to see Item
changes reflected in Collection.history
.
For example, if a new Item
is added to a collection, I would like to have a new entry in Collection.history
.
Is this somehow possible?
EDIT:
some more details on what I want to do:
Basically whenever something inside a Collection
changes, I would like to have a snapshot to be able to do diffs.
So for example, the description
is changed, then I can simply diff between the two snapshots to see what changed. This works well with simple-history.
Now what doesn't work is that whenever an Item
is changed/added/removed, the new state is not reflected in the history of my Collection
. Consider:
c = Collection.objects.get(id=123)
item = Item.objects.get(id=456)
c.items.add(item)
If I check c.history
, there is no way to know that item
was added to the collection as far as i can tell.