diff --git a/CHANGES.rst b/CHANGES.rst index 049e39f75..cddf8c125 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -16,6 +16,7 @@ Unreleased version is lower than 4.2 (gh-1261) - Small performance optimization of the ``clean-duplicate_history`` command (gh-1015) - Support Simplified Chinese translation (gh-1281) +- Fixed error in history view of object with forward slash in primary key (gh-1295) 3.4.0 (2023-08-18) ------------------ diff --git a/simple_history/admin.py b/simple_history/admin.py index 34e3033fe..7c5e74e58 100644 --- a/simple_history/admin.py +++ b/simple_history/admin.py @@ -126,6 +126,7 @@ def history_form_view(self, request, object_id, version_id, extra_context=None): model = getattr( self.model, self.model._meta.simple_history_manager_attribute ).model + object_id = unquote(str(object_id)) obj = get_object_or_404( model, **{original_opts.pk.attname: object_id, "history_id": version_id} ).instance diff --git a/simple_history/models.py b/simple_history/models.py index 6dc4db9e8..70a0461c7 100644 --- a/simple_history/models.py +++ b/simple_history/models.py @@ -7,6 +7,7 @@ from django.apps import apps from django.conf import settings from django.contrib import admin +from django.contrib.admin.utils import quote from django.contrib.auth import get_user_model from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist from django.db import models @@ -484,7 +485,7 @@ def revert_url(self): app_label, model_name = opts.app_label, opts.model_name return reverse( f"{admin.site.name}:{app_label}_{model_name}_simple_history", - args=[getattr(self, opts.pk.attname), self.history_id], + args=[quote(getattr(self, opts.pk.attname)), self.history_id], ) def get_instance(self): diff --git a/simple_history/templates/simple_history/_object_history_list.html b/simple_history/templates/simple_history/_object_history_list.html index 0dd575cc5..879e49433 100644 --- a/simple_history/templates/simple_history/_object_history_list.html +++ b/simple_history/templates/simple_history/_object_history_list.html @@ -19,7 +19,7 @@
{% for action in action_list %}