mirror of https://github.com/django/django.git
Fixed #10448: correcting errors on "save as new" now correctly create a new object instead of modifying the old one. Thanks, bastih.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10713 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
38a6c48878
commit
23fa913676
|
@ -780,7 +780,7 @@ class ModelAdmin(BaseModelAdmin):
|
|||
'app_label': opts.app_label,
|
||||
}
|
||||
context.update(extra_context or {})
|
||||
return self.render_change_form(request, context, add=True)
|
||||
return self.render_change_form(request, context, form_url=form_url, add=True)
|
||||
add_view = transaction.commit_on_success(add_view)
|
||||
|
||||
def change_view(self, request, object_id, extra_context=None):
|
||||
|
@ -803,7 +803,7 @@ class ModelAdmin(BaseModelAdmin):
|
|||
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_unicode(opts.verbose_name), 'key': escape(object_id)})
|
||||
|
||||
if request.method == 'POST' and request.POST.has_key("_saveasnew"):
|
||||
return self.add_view(request, form_url='../../add/')
|
||||
return self.add_view(request, form_url='../add/')
|
||||
|
||||
ModelForm = self.get_form(request, obj)
|
||||
formsets = []
|
||||
|
|
|
@ -174,6 +174,7 @@ class PersonAdmin(admin.ModelAdmin):
|
|||
list_filter = ('gender',)
|
||||
search_fields = (u'name',)
|
||||
ordering = ["id"]
|
||||
save_as = True
|
||||
|
||||
class Persona(models.Model):
|
||||
"""
|
||||
|
|
|
@ -234,6 +234,34 @@ class AdminViewBasicTest(TestCase):
|
|||
"Changelist filter isn't showing options contained inside a model field 'choices' option named group."
|
||||
)
|
||||
|
||||
class SaveAsTests(TestCase):
|
||||
fixtures = ['admin-views-users.xml','admin-views-person.xml']
|
||||
|
||||
def setUp(self):
|
||||
self.client.login(username='super', password='secret')
|
||||
|
||||
def tearDown(self):
|
||||
self.client.logout()
|
||||
|
||||
def test_save_as_duplication(self):
|
||||
"""Ensure save as actually creates a new person"""
|
||||
post_data = {'_saveasnew':'', 'name':'John M', 'gender':1}
|
||||
response = self.client.post('/test_admin/admin/admin_views/person/1/', post_data)
|
||||
self.assertEqual(len(Person.objects.filter(name='John M')), 1)
|
||||
self.assertEqual(len(Person.objects.filter(id=1)), 1)
|
||||
|
||||
def test_save_as_display(self):
|
||||
"""
|
||||
Ensure that 'save as' is displayed when activated and after submitting
|
||||
invalid data aside save_as_new will not show us a form to overwrite the
|
||||
initial model.
|
||||
"""
|
||||
response = self.client.get('/test_admin/admin/admin_views/person/1/')
|
||||
self.assert_(response.context['save_as'])
|
||||
post_data = {'_saveasnew':'', 'name':'John M', 'gender':3, 'alive':'checked'}
|
||||
response = self.client.post('/test_admin/admin/admin_views/person/1/', post_data)
|
||||
self.assertEqual(response.context['form_url'], '../add/')
|
||||
|
||||
class CustomModelAdminTest(AdminViewBasicTest):
|
||||
urlbit = "admin2"
|
||||
|
||||
|
|
Loading…
Reference in New Issue