#21946: Calling get_object() on DeleteView resets the success_url -------------------------------+-------------------- Reporter: django@… | Owner: nobody Type: Uncategorized | Status: new Component: Generic views | Version: 1.6 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------- I was trying to do something with the object in the `def delete(self, request, *args, **kwargs)` method for a `DeleteView`, but found that calling `self.get_object()` *after* calling through to `super().delete(...)` causes problems:
{{{ class MyDeleteView(DeleteView): success_url = "/finish/" def delete(self, request, *args, **kwargs): response = super(MyDeleteView, self).delete(request, *args, **kwargs) object = self.get_object() # ... do something with object (or not) return response # urls.py: ... url(r'^thing/delete/(?P<pk>\d+)/, views.MyDeleteView.as_view(), name="thing_delete") ... }}} I'd expect this code to work, and that upon returning response you are redirected to `success_url` (i.e. `/finish/`). Instead, you are redirected back to the delete page, so if my `Thing` has a `pk=1`, then I would be redirected to `/thing/delete/1/` Now if I call `get_object()` *before* the call through to `super` everything works fine. It seems calling `get_object()` resets the `success_url`. I'm not sure if what I'm trying to do is not normal behaviour, but I'd have thought that trying to do something once an object has successfully been delete (i.e. only *after* the call to `super(...).delete(...)` has been made) should be OK. In this case, I'm trying to send an email saying `"Successfully deleted {object}"` -- Ticket URL: <https://code.djangoproject.com/ticket/21946> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.eb2d983d3be3d32c4fcfd1d4be6939b6%40djangoproject.com. For more options, visit https://groups.google.com/groups/opt_out.