-
Notifications
You must be signed in to change notification settings - Fork 432
Description
Quick question: it turns out my project needs additional data in or from a LogEntry
instance and I'm asking how to extend auditlog without requiring too much work. I'm still a bit new to python and django, and I'm looking to minimize the impact of changes. I appreciate any thoughts and pointers. Also, thanks for this package. It's been really useful.
What is driving this is a need to collect some of the relationship references for building a report that includes deleted objects. The report works well for create and update actions. For these, the following code works fine (record
is an auditlog.LogEntry
):
changed_object_type = record.content_type
changed_object = changed_object_type.get_object_for_this_type(id=record.object_id)
From changed_object
, I can find all the connected objects. For example, a student
might have an assessment
, which creates the LogEntry
. The report calls for an attribute of the related student.
If assessment
was deleted, getting the related object isn't so easy - pulling up the (deleted) instance throws an ObjectNotFound exception. I have a workaround at present, but it's a bit of hackery.
For example one idea that might solve this could be to change what is in record.changes
. Right now, changes
has 'student': 'Mike'
and what might be easiest would be to change that entry to
'student': [('printname', 'Mike), ('content_type', 'django_content_type_value'), ('object_id', 'related_obj_id')] (or a dict or whatever)
I intend on experimenting to figure this out. But I have learned the hard way in the past that there's often a gotcha or three, especially when I don't fully understand something Any thoughts?
Thanks,
Mike