From 6298ffe783e4261a47d87a68eb7b8cb241eb3e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Claver=20DIBY?= <75357402+Stefan-ci@users.noreply.github.com> Date: Sat, 6 Jan 2024 20:46:42 +0100 Subject: [PATCH] Get the edited object like in Django LogEntry() model I know it's possible to get the edited object in a python code but hard in templates. So having a method to query/get the edited object directly would be a benefit (easier). --- .gitignore | 1 + easyaudit/models.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 4002ae3..26466f3 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,4 @@ ENV/ # Rope project settings .ropeproject .idea +.DS_Store diff --git a/easyaudit/models.py b/easyaudit/models.py index 65b3a3c..fff6614 100644 --- a/easyaudit/models.py +++ b/easyaudit/models.py @@ -52,6 +52,10 @@ def is_update(self): def is_delete(self): return self.DELETE == self.event_type + + def get_edited_object(self): + """ Return the edited object represented by this CRUD event (Like Django LogEntry does). """ + return self.content_type.get_object_for_this_type(pk=self.object_id) class Meta: verbose_name = _('CRUD event')