diff --git a/django/views/generic/edit.py b/django/views/generic/edit.py
index 97a6c0a..5b97fc8 100644
a
|
b
|
class DeletionMixin(object):
|
242 | 242 | redirects to the success URL. |
243 | 243 | """ |
244 | 244 | self.object = self.get_object() |
| 245 | success_url = self.get_success_url() |
245 | 246 | self.object.delete() |
246 | | return HttpResponseRedirect(self.get_success_url()) |
| 247 | return HttpResponseRedirect(success_url) |
247 | 248 | |
248 | 249 | # Add support for browsers which only accept GET and POST for now. |
249 | 250 | def post(self, *args, **kwargs): |
… |
… |
class DeletionMixin(object):
|
251 | 252 | |
252 | 253 | def get_success_url(self): |
253 | 254 | if self.success_url: |
254 | | return self.success_url |
| 255 | return self.success_url % self.object.__dict__ |
255 | 256 | else: |
256 | 257 | raise ImproperlyConfigured( |
257 | 258 | "No URL to redirect to. Provide a success_url.") |
diff --git a/docs/ref/class-based-views/mixins-editing.txt b/docs/ref/class-based-views/mixins-editing.txt
index bce3c84..844171c 100644
a
|
b
|
ProcessFormView
|
201 | 201 | The url to redirect to when the nominated object has been |
202 | 202 | successfully deleted. |
203 | 203 | |
| 204 | .. versionadded:: 1.6 |
| 205 | |
| 206 | ``success_url`` may contain dictionary string formatting, which |
| 207 | will be interpolated against the object's field attributes. For |
| 208 | example, you could use ``success_url="/parent/%(parent_id)s/"`` to |
| 209 | redirect to a URL composed out of the ``parent_id`` field on a model. |
| 210 | |
204 | 211 | .. method:: get_success_url(obj) |
205 | 212 | |
206 | 213 | Returns the url to redirect to when the nominated object has been |
diff --git a/docs/releases/1.6.txt b/docs/releases/1.6.txt
index f53fa8a..5d61517 100644
a
|
b
|
Minor features
|
64 | 64 | :attr:`~django.core.management.BaseCommand.leave_locale_alone` internal |
65 | 65 | option. See :ref:`management-commands-and-locales` for more details. |
66 | 66 | |
| 67 | * The :attr:`~django.views.generic.edit.DeletionMixin.success_url` of |
| 68 | :class:`~django.views.generic.edit.DeletionMixin` is now interpolated with |
| 69 | its ``object``\'s ``__dict__``. |
| 70 | |
67 | 71 | Backwards incompatible changes in 1.6 |
68 | 72 | ===================================== |
69 | 73 | |
diff --git a/tests/regressiontests/generic_views/edit.py b/tests/regressiontests/generic_views/edit.py
index 0f1eb3c..3bacc31 100644
a
|
b
|
from .models import Artist, Author
|
13 | 13 | |
14 | 14 | |
15 | 15 | class FormMixinTests(TestCase): |
16 | | def test_initial_data(self): |
17 | | """ Test instance independence of initial data dict (see #16138) """ |
18 | | initial_1 = FormMixin().get_initial() |
19 | | initial_1['foo'] = 'bar' |
20 | | initial_2 = FormMixin().get_initial() |
21 | | self.assertNotEqual(initial_1, initial_2) |
| 16 | def test_initial_data(self): |
| 17 | """ Test instance independence of initial data dict (see #16138) """ |
| 18 | initial_1 = FormMixin().get_initial() |
| 19 | initial_1['foo'] = 'bar' |
| 20 | initial_2 = FormMixin().get_initial() |
| 21 | self.assertNotEqual(initial_1, initial_2) |
22 | 22 | |
23 | 23 | |
24 | 24 | class BasicFormTests(TestCase): |
… |
… |
class DeleteViewTests(TestCase):
|
283 | 283 | self.assertRedirects(res, 'http://testserver/edit/authors/create/') |
284 | 284 | self.assertQuerysetEqual(Author.objects.all(), []) |
285 | 285 | |
| 286 | def test_delete_with_interpolated_redirect(self): |
| 287 | a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'}) |
| 288 | res = self.client.post('/edit/author/%d/delete/interpolate_redirect/' % a.pk) |
| 289 | self.assertEqual(res.status_code, 302) |
| 290 | self.assertRedirects(res, 'http://testserver/edit/authors/create/?deleted=%d' % a.pk) |
| 291 | self.assertQuerysetEqual(Author.objects.all(), []) |
| 292 | |
286 | 293 | def test_delete_with_special_properties(self): |
287 | 294 | a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'}) |
288 | 295 | res = self.client.get('/edit/author/%d/delete/special/' % a.pk) |
diff --git a/tests/regressiontests/generic_views/urls.py b/tests/regressiontests/generic_views/urls.py
index 5730905..695b502 100644
a
|
b
|
urlpatterns = patterns('',
|
97 | 97 | views.NaiveAuthorDelete.as_view()), |
98 | 98 | (r'^edit/author/(?P<pk>\d+)/delete/redirect/$', |
99 | 99 | views.NaiveAuthorDelete.as_view(success_url='/edit/authors/create/')), |
| 100 | (r'^edit/author/(?P<pk>\d+)/delete/interpolate_redirect/$', |
| 101 | views.NaiveAuthorDelete.as_view(success_url='/edit/authors/create/?deleted=%(id)s')), |
100 | 102 | (r'^edit/author/(?P<pk>\d+)/delete/$', |
101 | 103 | views.AuthorDelete.as_view()), |
102 | 104 | (r'^edit/author/(?P<pk>\d+)/delete/special/$', |