From 5648e421d9fb4a8594acbe3706cd17d58ba26da2 Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Tue, 14 May 2024 17:01:22 +0200 Subject: [PATCH] feat(generic): introduce success_url getters for create and update This way they can be overridden by the inheriting object. The create_success_url now points to the absolute_url of the instance. Closes: #834 --- apis_core/generic/abc.py | 6 ++++++ apis_core/generic/views.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apis_core/generic/abc.py b/apis_core/generic/abc.py index 8f44ef8df..53daf8593 100644 --- a/apis_core/generic/abc.py +++ b/apis_core/generic/abc.py @@ -26,6 +26,12 @@ def get_delete_url(self): ct = ContentType.objects.get_for_model(self) return reverse("apis_core:generic:delete", args=[ct, self.id]) + def get_create_success_url(self): + return self.get_absolute_url() + + def get_update_success_url(self): + return self.get_edit_url() + @classmethod def get_change_permission(self): return permission_fullname("change", self) diff --git a/apis_core/generic/views.py b/apis_core/generic/views.py index ec758d286..be9f945d9 100644 --- a/apis_core/generic/views.py +++ b/apis_core/generic/views.py @@ -154,7 +154,7 @@ def get_form_class(self): return modelform_factory(self.model, form_class) def get_success_url(self): - return self.object.get_edit_url() + return self.object.get_create_success_url() class Delete(GenericModelMixin, PermissionRequiredMixin, DeleteView): @@ -198,7 +198,7 @@ def get_form_class(self): return modelform_factory(self.model, form_class) def get_success_url(self): - return self.object.get_edit_url() + return self.object.get_update_success_url() class Autocomplete(