Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed #19044 -- Allow get_success_url to access self.object in DeletionMixin #417

Closed
wants to merge 1 commit into from

4 participants

@0x0badc0de

generic_views tests passes

@mjtamlyn
Collaborator

I don't think the get_success_url method needs to change - it seems a pretty odd change to me anyway. The change to delete looks good though and makes sense.

@0x0badc0de

Please take a look at https://code.djangoproject.com/ticket/19044
Change to get_success_url is necessary for example to redirect to object parent after its deletion

@charettes
Collaborator

IMHO you shouldn't refer to an URL this way, you should use the reverse_lazy function here.

I have to agree with @mjtamlyn about the changes of the get_success_url method. You just can't assume that the specified success_url should be formatted using the instance's __dict__.

@0x0badc0de

Why get_success_url of DeletionMixin cannot format url in the same way as get_success_url of ModelFormMixin in the same file?

@mjtamlyn
Collaborator

Sorry, didn't realise it was a consistency thing. In that case the change should be there for consistency purposes, although I still think the feature smells ;)

@charettes
Collaborator

@0x0badc0de please forgive me, didn't notice that. I wonder if it's documented somewhere.

@apollo13
Owner

Needs tests as noted on the ticket.

@charettes
Collaborator

#663 has tests.

@charettes charettes closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 2 deletions.
  1. +3 −2 django/views/generic/edit.py
View
5 django/views/generic/edit.py
@@ -240,8 +240,9 @@ def delete(self, request, *args, **kwargs):
redirects to the success URL.
"""
self.object = self.get_object()
+ success_url = self.get_success_url()
self.object.delete()
- return HttpResponseRedirect(self.get_success_url())
+ return HttpResponseRedirect(success_url)
# Add support for browsers which only accept GET and POST for now.
def post(self, *args, **kwargs):
@@ -249,7 +250,7 @@ def post(self, *args, **kwargs):
def get_success_url(self):
if self.success_url:
- return self.success_url
+ return self.success_url % self.object.__dict__
else:
raise ImproperlyConfigured(
"No URL to redirect to. Provide a success_url.")
Something went wrong with that request. Please try again.