Code

Ticket #10640: add_form.patch

File add_form.patch, 3.3 KB (added by jcsackett, 4 years ago)

Patch to add the requested behavior

  • django/contrib/admin/options.py

     
    585585            'save_on_top': self.save_on_top, 
    586586            'root_path': self.admin_site.root_path, 
    587587        }) 
     588        if add: 
     589            admin_form_template = getattr(self, 'add_form_template', None) 
     590        else: 
     591            admin_form_template = getattr(self, 'change_form_template', None) 
    588592        context_instance = template.RequestContext(request, current_app=self.admin_site.name) 
    589         return render_to_response(self.change_form_template or [ 
     593        return render_to_response(admin_form_template or [ 
    590594            "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()), 
    591595            "admin/%s/change_form.html" % app_label, 
    592596            "admin/change_form.html" 
  • tests/regressiontests/admin_views/tests.py

     
    541541        self.failUnlessEqual(request.status_code, 200) 
    542542        self.assert_("var hello = 'Hello!';" in request.content) 
    543543        self.assertTemplateUsed(request, 'custom_admin/change_list.html') 
    544  
    545         # Test custom change form template 
     544         
     545        # Test custom add form template 
    546546        request = self.client.get('/test_admin/admin/admin_views/customarticle/add/') 
    547         self.assertTemplateUsed(request, 'custom_admin/change_form.html') 
    548  
    549         # Add an article so we can test delete and history views 
     547        self.assertTemplateUsed(request, 'custom_admin/add_form.html') 
     548         
     549        # Add an article so we can test delete, change, and history views 
    550550        post = self.client.post('/test_admin/admin/admin_views/customarticle/add/', { 
    551551            'content': '<p>great article</p>', 
    552552            'date_0': '2008-03-18', 
     
    555555        self.assertRedirects(post, '/test_admin/admin/admin_views/customarticle/') 
    556556        self.failUnlessEqual(CustomArticle.objects.all().count(), 1) 
    557557 
    558         # Test custom delete and object history templates 
     558        # Test custom delete, change, and object history templates 
     559        # Test custom change form template 
     560        request = self.client.get('/test_admin/admin/admin_views/customarticle/1/') 
     561        self.assertTemplateUsed(request, 'custom_admin/change_form.html') 
    559562        request = self.client.get('/test_admin/admin/admin_views/customarticle/1/delete/') 
    560563        self.assertTemplateUsed(request, 'custom_admin/delete_confirmation.html') 
    561564        request = self.client.get('/test_admin/admin/admin_views/customarticle/1/history/') 
  • tests/regressiontests/admin_views/models.py

     
    106106    """ 
    107107    change_list_template = 'custom_admin/change_list.html' 
    108108    change_form_template = 'custom_admin/change_form.html' 
     109    add_form_template = 'custom_admin/add_form.html' 
    109110    object_history_template = 'custom_admin/object_history.html' 
    110111    delete_confirmation_template = 'custom_admin/delete_confirmation.html' 
    111112