I have a model with a text field, that needs to be versioned.
class Book(models.Model):
title = models.CharField(max_length=100)
summary = models.TextField()
The expected behavior is as follows:
- If i create a new book with a summary, the text will be saved normally
- If the summary is updated, the old state needs to be stored somewhere with a version number and timestamp
- It should be easily possible to query for the current, a range of or specific versions
- Only the field
summaryshould be versioned, not the whole model
How should i do this?
Got it myself.
First create a new model called
SummaryHistory:Now extend the initial model as follows:
Now, every time you update a book, a new incremented version of the summary for the specific book will be created unless it has not changed.