views:

152

answers:

3

Hi folks!!

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?

+2  A: 

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

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

Oli
Database journaling seems like overkill if I'm reading the OP correctly.
msw
@Oli I wish I knew about this some time ago, had to implement a wiki from scratch. This would have helped a lot. Btw for this purpose, it might be a bit too bloated. In any case, thank you very much!!
RadiantHex
+1  A: 

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.

msw
@msw: I'm doing it as you suggested. Thanks for that, Python logging is indeed quite powerful. :)
RadiantHex
+1  A: 

I've had similar situation in which we were supposed to keep the history of changed. But we also needed audit to track who made the changes and the ability to revert. In our approach storing in database seemed more logical. However considering you have statistical data and it's gonnna be large, perhaps separate file based approach would be better for you.

In any case you should use a generic mechanism to log the changes on models rather than coding each model invidually.

Take a look at this: http://www.djangosnippets.org/snippets/1052/

sharjeel
@sharjeel that is awesome! Thanks!
RadiantHex