Skip to content

Commit

Permalink
feat(generic): introduce success_url getters for create and update
Browse files Browse the repository at this point in the history
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
  • Loading branch information
b1rger committed May 14, 2024
1 parent 4587783 commit 5648e42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions apis_core/generic/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions apis_core/generic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 5648e42

Please sign in to comment.