Ticket #11250: admin_can_delete.diff
File admin_can_delete.diff, 4.9 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/options.py
1109 1109 fk_name = None 1110 1110 formset = BaseInlineFormSet 1111 1111 extra = 3 1112 can_delete = True 1112 1113 max_num = 0 1113 1114 template = None 1114 1115 verbose_name = None … … 1154 1155 "exclude": (exclude + kwargs.get("exclude", [])) or None, 1155 1156 "formfield_callback": curry(self.formfield_for_dbfield, request=request), 1156 1157 "extra": self.extra, 1158 "can_delete": self.can_delete, 1157 1159 "max_num": self.max_num, 1158 1160 } 1159 1161 defaults.update(kwargs) -
django/contrib/contenttypes/generic.py
386 386 "formfield_callback": self.formfield_for_dbfield, 387 387 "formset": self.formset, 388 388 "extra": self.extra, 389 "can_delete": True,389 "can_delete": self.can_delete, 390 390 "can_order": False, 391 391 "fields": fields, 392 392 "max_num": self.max_num, -
tests/regressiontests/generic_inline_admin/tests.py
5 5 from django.contrib.contenttypes.generic import generic_inlineformset_factory 6 6 7 7 # local test models 8 from models import Episode, EpisodeExtra, Episode MaxNum, EpisodeExclude, Media8 from models import Episode, EpisodeExtra, EpisodeCanDelete, EpisodeMaxNum, EpisodeExclude, Media 9 9 10 10 class GenericAdminViewTest(TestCase): 11 11 fixtures = ['users.xml'] … … 121 121 self.assertEqual(formset.total_form_count(), 1) 122 122 self.assertEqual(formset.initial_form_count(), 1) 123 123 124 def testCanDeleteParam(self): 125 """ 126 With can_delete=False, there should be no ability to delete. 127 """ 128 e = self._create_object(EpisodeCanDelete) 129 response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/episodecandelete/%s/' % e.pk) 130 formset = response.context['inline_admin_formsets'][0].formset 131 self.assertEqual(formset.can_delete, False) 132 124 133 def testMaxNumParam(self): 125 134 """ 126 135 With extra=5 and max_num=2, there should be only 2 forms. … … 139 148 e = self._create_object(EpisodeExclude) 140 149 response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/episodeexclude/%s/' % e.pk) 141 150 formset = response.context['inline_admin_formsets'][0].formset 142 self.failIf('url' in formset.forms[0], 'The formset has excluded "url" field.') 151 self.failIf('url' in formset.forms[0], 'The formset has excluded "url" field.') 152 -
tests/regressiontests/generic_inline_admin/models.py
46 46 admin.site.register(EpisodeExtra, inlines=[MediaExtraInline]) 47 47 48 48 # 49 # Generic inline with can_delete = True 50 # 51 52 class EpisodeCanDelete(Episode): 53 pass 54 55 class MediaCanDeleteInline(generic.GenericTabularInline): 56 model = Media 57 can_delete = False 58 59 admin.site.register(EpisodeCanDelete, inlines=[MediaCanDeleteInline]) 60 61 # 49 62 # Generic inline with extra and max_num 50 63 # 51 64 -
tests/regressiontests/modeladmin/models.py
908 908 ... inlines = [ValidationTestInline] 909 909 >>> validate(ValidationTestModelAdmin, ValidationTestModel) 910 910 911 # can_delete 912 913 >>> class ValidationTestInline(TabularInline): 914 ... model = ValidationTestInlineModel 915 ... can_delete = False 916 >>> class ValidationTestModelAdmin(ModelAdmin): 917 ... inlines = [ValidationTestInline] 918 >>> validate(ValidationTestModelAdmin, ValidationTestModel) 919 911 920 # max_num 912 921 913 922 >>> class ValidationTestInline(TabularInline): -
docs/ref/contrib/admin/index.txt
987 987 to the initial forms. See the 988 988 :ref:`formsets documentation <topics-forms-formsets>` for more information. 989 989 990 ``can_delete`` 991 ~~~~~~~~~~~~~~ 992 993 The value for ``can_delete`` defaults to ``True``. This controls the ability 994 to delete relations in the formset. See the 995 :ref:`formsets documentation <topics-forms-formsets>` for more information. 996 990 997 ``max_num`` 991 998 ~~~~~~~~~~~ 992 999