Open farcepest opened 13 years ago
Yes, it's clear. I think the best solution would be to null out that field in the audited model.
The problem is also that Django, when asked to delete an instance, deletes all other objects related to this object by default, including any audit logs. Thus, in the audit log the foreign key field needs to be nullable and a on_delete needs to be SET_NULL. Disadvantage: You will not be able to find out what the original foreign key was after it has been set to Null.
I'm currenty using django-audit-log in a project that is stuck in django 1.1, so there's no way to use these settings anyway (which have been introduced with Django 1.3). I'm working on a branch where ForeignKey fields are mapped to IntegerFields (or whatever the Foreign Key relates to). With this approach, you do not need to modify anything to Null because the referenced object is removed, so you can always reconstruct all changes fully from the audit log.
https://github.com/mradziej/django-audit-log/commits/remove-foreign-keys
If you delete a non-audited object which is referred to by an audited object's audit log entries, IntegrityErrors result. This is because create_log_entry_model() copies all fields from the original model, including the foreign key restraints.
If this is not clear, let me know and I'll try to work up a test case.