Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping track of changes - Django

I have various models of which I would like to keep track and collect statistical data.

The problem is how to store the changes throughout time.

I thought of various alternative:

  • Storing a log in a TextField, open it and update it every time the model is saved.
  • Alternatively pickle a list and store it in a TextField.
  • Save logs on hard drive.

What are your suggestions?

like image 350
RadiantHex Avatar asked Mar 23 '10 23:03

RadiantHex


2 Answers

Don't reinvent the wheel.. Use django-reversion for logging changes.

I'd break statistics off into a separate model though.

like image 85
Oli Avatar answered Oct 17 '22 01:10

Oli


Quoth my elementary chemistry teacher: "If you don't write it down, it didn't happen", therefore save logs in a file.

Since the log information is disjoint from your application data (it's meta-data, actually), keep them separate. You could log to a database table but it should be distinct from your model.

Text pickle data is difficult for humans to read, binary pickle data even more so; log in an easily parsed format and the data can be imported into analysis software easily.

like image 34
msw Avatar answered Oct 17 '22 02:10

msw