How to make history for a model that show me the old value and the new changed value in a field?
In my mind i think to make history model to each model which have the same fields and when the user create new or update the data from the first model go to the second model too.
I searched alot for this problem and i found a packet called django-reversion but i didn't understand it how to make it store the old value and new value if any one can help me for this problem please tell me.
To allow viewing previous model versions on the Django admin site, inherit from the simple_history. admin. SimpleHistoryAdmin class when registering your model with the admin site. This will replace the history object page on the admin site and allow viewing and reverting to previous model versions.
Once you have defined your models, you need to tell Django you're going to use those models. Do this by editing your settings file and changing the INSTALLED_APPS setting to add the name of the module that contains your models.py .
TimeStampedModel - An Abstract Base Class model that provides self-managed created and modified fields.
Each field has a set of arguments for setting column properties. For example, to define the varchar database, CharField requires max_length. These are called Field options in Django model data types and field lists.
For this purpose you can use simple-history app
Every changes of your instance will be reflected in historical table. There would be new row with new values for each changes. so you can reproduce all old values for each field.
In this link there is a comparisson of different packages that can be used for audit/history of models.
I use django-simple-history which comes with a nice integration to view the list of changes of every model instance in the admin.
For my use case at least, django-simple-history provided me with what I needed, and so far I did not face any issues with it.
EDIT: just an additional note
This package does NOT track history of ManyToManyField
.
See also these related questions:
And the Github issue:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With