1👍
It’s possible, but something that is likely to be coded at the application/view layer rather than directly in the Django models. What you’re attempting appears to closely match the log entries that are created as part of the standard django.contrib.admin
application so you should look in this app for ideas. django.contrib.admin
will log an entry to a LogEntry
table every time an object is updated, created or deleted in the admin interface.
It’s likely for your application that you’ll need to store changes in model content such as a change in a task description, not simply whether a task was created. To achieve this, you’re likely to require both the current task object and the updated task details to be able to create a TaskHistory
object.
Each view that is capable of modifying a task would also include logic which could create a TaskHistory
object, and save both the updated/new Task
and the TaskHistory
objects as independent model objects, possibly wrapped in a database level transaction to make the changes appear atomically.