mirror of
https://github.com/django/django.git
synced 2024-12-24 18:16:19 +00:00
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
This commit is contained in:
parent
bce890ace4
commit
d68666700f
@ -1146,7 +1146,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||
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
|
||||
|
@ -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()
|
||||
|
@ -3160,3 +3160,22 @@ class AdminCustomSaveRelatedTests(TestCase):
|
||||
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user