Ticket #9071: disable_add_r15922.diff
File disable_add_r15922.diff, 3.5 KB (added by , 14 years ago) |
---|
-
docs/ref/contrib/admin/index.txt
261 261 ``django.utils.html.escape()`` to escape any HTML special 262 262 characters. 263 263 264 .. attribute:: ModelAdmin.exclude_add 265 266 Disable the related field "add another" popup for any field listed. 267 268 For example:: 269 270 class BookAdmin(admin.ModelAdmin): 271 exclude_add = ['author'] 272 273 In the admin form for the Book model, the author field will appear without 274 the popup link next to it. 275 264 276 .. attribute:: ModelAdmin.filter_horizontal 265 277 266 278 By default, a :class:`~django.db.models.ManyToManyField` is displayed in -
tests/regressiontests/admin_views/tests.py
116 116 response = self.client.post('/test_admin/%s/admin_views/section/add/' % self.urlbit, post_data) 117 117 self.assertEqual(response.status_code, 302) # redirect somewhere 118 118 119 def testExcludeAdd(self): 120 """ 121 Test if we can disable "add" popup links in the admin 122 """ 123 response = self.client.get(reverse('admin:admin_views_answer_add')) 124 self.assertNotContains(response, """<a href="/test_admin/admin/admin_views/question/add/" class="add-another" id="add_id_question" onclick="return showAddAnotherPopup(this);"> <img src="/static/admin/img/admin/icon_addlink.gif" width="10" height="10" alt="Add Another"/></a>""") 125 119 126 def testPopupAddPost(self): 120 127 """ 121 128 Ensure http response from a popup is properly escaped. -
tests/regressiontests/admin_views/models.py
676 676 def __unicode__(self): 677 677 return self.answer 678 678 679 class AnswerAdmin(admin.ModelAdmin): 680 exclude_add = ['question'] 681 679 682 class Reservation(models.Model): 680 683 start_date = models.DateTimeField() 681 684 price = models.IntegerField() … … 817 820 admin.site.register(Topping) 818 821 admin.site.register(Album, AlbumAdmin) 819 822 admin.site.register(Question) 820 admin.site.register(Answer )823 admin.site.register(Answer, AnswerAdmin) -
django/contrib/admin/options.py
70 70 formfield_overrides = {} 71 71 readonly_fields = () 72 72 ordering = None 73 exclude_add = [] 73 74 74 75 def __init__(self): 75 76 overrides = FORMFIELD_FOR_DBFIELD_DEFAULTS.copy() … … 113 114 related_modeladmin = self.admin_site._registry.get( 114 115 db_field.rel.to) 115 116 can_add_related = bool(related_modeladmin and 116 related_modeladmin.has_add_permission(request)) 117 related_modeladmin.has_add_permission(request) and 118 db_field.name not in self.exclude_add) 117 119 formfield.widget = widgets.RelatedFieldWidgetWrapper( 118 120 formfield.widget, db_field.rel, self.admin_site, 119 121 can_add_related=can_add_related)