From dc8eec5d1e8bb5ae0315d47c0a5de22a780229c7 Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Thu, 25 Apr 2024 19:44:25 +0200 Subject: [PATCH] fix(history): add a get_absolute_url method to APISHistoryTableBase The historical models use `history_id` as id instead of the `id` of the instance they refer to. We therefore override the `get_absolute_url` method, so that it points to the historical record and not to the instance it refers to. --- apis_core/history/models.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apis_core/history/models.py b/apis_core/history/models.py index 46740ceda..31e408eeb 100644 --- a/apis_core/history/models.py +++ b/apis_core/history/models.py @@ -96,6 +96,10 @@ def set_version_tag(self, tag: str, include_triples: bool = True): triple.save() self.save() + def get_absolute_url(self): + ct = ContentType.objects.get_for_model(self) + return reverse("apis_core:generic:detail", args=[ct, self.history_id]) + class VersionMixin(models.Model): history = APISHistoricalRecords(