Ticket #16604: save_related_in_changelist_view.diff
File save_related_in_changelist_view.diff, 2.5 KB (added by , 13 years ago) |
---|
-
django/contrib/admin/options.py
1145 1145 if form.has_changed(): 1146 1146 obj = self.save_form(request, form, change=True) 1147 1147 self.save_model(request, obj, form, change=True) 1148 form.save_m2m()1148 self.save_related(request, form, formsets=[], change=True) 1149 1149 change_msg = self.construct_change_message(request, form, None) 1150 1150 self.log_change(request, obj, change_msg) 1151 1151 changecount += 1 -
tests/regressiontests/admin_views/tests.py
3160 3160 3161 3161 self.assertEqual('Josh Stone', Parent.objects.latest('id').name) 3162 3162 self.assertEqual([u'Catherine Stone', u'Paul Stone'], children_names) 3163 3164 def test_should_be_able_to_edit_related_objects_on_changelist_view(self): 3165 parent = Parent.objects.create(name='Josh Rock') 3166 paul = Child.objects.create(parent=parent, name='Paul') 3167 catherine = Child.objects.create(parent=parent, name='Catherine') 3168 post = { 3169 'form-TOTAL_FORMS': '1', 3170 'form-INITIAL_FORMS': '1', 3171 'form-MAX_NUM_FORMS': '0', 3172 'form-0-id': parent.id, 3173 'form-0-name': 'Josh Stone', 3174 '_save': 'Save' 3175 } 3176 3177 response = self.client.post('/test_admin/admin/admin_views/parent/', post) 3178 3179 children_names = list(Child.objects.order_by('name').values_list('name', flat=True)) 3180 3181 self.assertEqual('Josh Stone', Parent.objects.latest('id').name) 3182 self.assertEqual([u'Catherine Stone', u'Paul Stone'], children_names) -
tests/regressiontests/admin_views/models.py
391 391 model = Parent 392 392 inlines = [ChildInline] 393 393 394 list_editable = ('name',) 395 394 396 def save_related(self, request, form, formsets, change): 395 397 super(ParentAdmin, self).save_related(request, form, formsets, change) 396 398 first_name, last_name = form.instance.name.split()