Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #16604 -- Use new save_related hook when saving objects on the …

…changelist, too. Thanks, pdeglopper.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16599 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d68666700fa3ca24701479bd0831c3dcfb9f5ab1 1 parent bce890a
@jezdez jezdez authored
View
2  django/contrib/admin/options.py
@@ -1146,7 +1146,7 @@ def changelist_view(self, request, extra_context=None):
if form.has_changed():
obj = self.save_form(request, form, change=True)
self.save_model(request, obj, form, change=True)
- form.save_m2m()
+ self.save_related(request, form, formsets=[], change=True)
change_msg = self.construct_change_message(request, form, None)
self.log_change(request, obj, change_msg)
changecount += 1
View
2  tests/regressiontests/admin_views/models.py
@@ -391,6 +391,8 @@ class ParentAdmin(admin.ModelAdmin):
model = Parent
inlines = [ChildInline]
+ list_editable = ('name',)
+
def save_related(self, request, form, formsets, change):
super(ParentAdmin, self).save_related(request, form, formsets, change)
first_name, last_name = form.instance.name.split()
View
19 tests/regressiontests/admin_views/tests.py
@@ -3160,3 +3160,22 @@ def test_should_be_able_to_edit_related_objects_on_change_view(self):
self.assertEqual('Josh Stone', Parent.objects.latest('id').name)
self.assertEqual([u'Catherine Stone', u'Paul Stone'], children_names)
+
+ def test_should_be_able_to_edit_related_objects_on_changelist_view(self):
+ parent = Parent.objects.create(name='Josh Rock')
+ paul = Child.objects.create(parent=parent, name='Paul')
+ catherine = Child.objects.create(parent=parent, name='Catherine')
+ post = {
+ 'form-TOTAL_FORMS': '1',
+ 'form-INITIAL_FORMS': '1',
+ 'form-MAX_NUM_FORMS': '0',
+ 'form-0-id': parent.id,
+ 'form-0-name': 'Josh Stone',
+ '_save': 'Save'
+ }
+
+ response = self.client.post('/test_admin/admin/admin_views/parent/', post)
+ children_names = list(Child.objects.order_by('name').values_list('name', flat=True))
+
+ self.assertEqual('Josh Stone', Parent.objects.latest('id').name)
+ self.assertEqual([u'Catherine Stone', u'Paul Stone'], children_names)
Please sign in to comment.
Something went wrong with that request. Please try again.