Let me produce a feature for my Django application much like Django admin's 'Recent Actions', to be able to store history info on my other models.
For instance say I've two models known as Book and Author. I wish to possess a third model that stores information for example what action was carried out on the given object inside a model (add, modify, remove, etc.) by who so when.
Who, when and also the action are easy, I am just unsure concerning how to store specifics of what object the experience was carried out on.
My primary idea was to possess a 'Transactions' model that will store these details, and both my Book and Author models will have a ForeignKey regards to it. However, basically remove the given book or author, then it's transaction history can also be erased and that i don't have any record this object was indeed erased.
I have been considering other possible solutions, but I decided to request for additional experienced opinions here first. How must i approach this issue and what exactly are some reasonable methods to it?
You might like to take a look at django-reversion -- With the idea to implement in order to study from it for your own personel implementation. Django reversion functions by saving details about the modification, together with a serialized copy from the item because it been around at that certain moment. Which means that you are able to later recall that certain specific item and perform a comparison or restoration or whatever.
If you choose to implement your personal custom solution, I'd recommend using Django's built-in signal sub-system. Django out-of-the-box offers the common signals for stuff you pointed out like model creation, saving, and removing. You could include in custom signals too should you found the requirement for them.
Using signals would permit you to develop the 'history' code outside of itOrWriter implementation code which over time is going to be an resource (instead of stringing history code through the Book/Author code). Again django-reversion works as a good reference here by doing its work almost entirely with signals.
IMHO the very best option would be the main one produced by Marty Alchin in the Pro Django book which regrettably is expensive but, fortunately, is really a book worth getting anyway.
An earlier version of his audit trail are available around the Django wiki at AuditTrail but I am unsure how good this code works in recent versions of Django.
Additionally you can try fullhistory that manage changes outdoors from the admin inteface. I'd some issues when testing it, however it may meet your needs.