Enrico, I've done this in the past. I didn't use Django directly for the audit tables. Instead I defined DB triggers on each primary table that inserted a row of audit values into the audit table. I can send you sample trigger code that works in Oracle and MySQL. The nice things about this approach are that Django can entirely ignore the audit tables, manipulating only the primary tables, and that audit table entries are ALWAYS created, even of you bypass Django and do a direct INSERT, UPDATE, or DELETE to a primary table. You should still be able to define the audit tables as Django models, to get the benefit of schema migrations, etc., and to make it easier to write an audit trail viewer. In my case, I didn't have an explicit "version" field in the primary tables, but you could have the triggers handle that also. Or you could do it in the Django save() method of each model, or in a custom manager. If you go the custom save() or custom manager route, you could do all of the work there, and avoid the need for triggers, but then it would be easy to bypass the audit table by doing a direct INSERT, UPDATE, or DELETE to a primary table. --Fred
Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/ Bristle Software, Inc -- http://bristle.com -- Glad to be of service! Open Source: Without walls and fences, we need no Windows or Gates. On 1/21/17 7:15 AM, enrico baranski
wrote:
-- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/88db55d7-f28b-3099-50a4-1ed3b674e5e4%40bristle.com. For more options, visit https://groups.google.com/d/optout. |
- audit trail functionality in database model enrico baranski
- Re: audit trail functionality in database model Mike Dewhirst
- Re: audit trail functionality in database model enrico baranski
- Re: audit trail functionality in database model Fred Stluka
- Re: audit trail functionality in database model enrico baranski
- Re: audit trail functionality in database mod... enrico baranski
- Re: audit trail functionality in database... Fred Stluka
- Re: audit trail functionality in database mod... Fred Stluka
- Re: audit trail functionality in database model Melvyn Sopacua
- Re: audit trail functionality in database model Ryan Castner
- Re: audit trail functionality in database model enrico baranski