Ticket #16604: save_related_in_changelist_view.diff

File save_related_in_changelist_view.diff, 2.5 KB (added by pdeglopper@…, 13 years ago)
  • django/contrib/admin/options.py

     
    11451145                    if form.has_changed():
    11461146                        obj = self.save_form(request, form, change=True)
    11471147                        self.save_model(request, obj, form, change=True)
    1148                         form.save_m2m()
     1148                        self.save_related(request, form, formsets=[], change=True)
    11491149                        change_msg = self.construct_change_message(request, form, None)
    11501150                        self.log_change(request, obj, change_msg)
    11511151                        changecount += 1
  • tests/regressiontests/admin_views/tests.py

     
    31603160
    31613161        self.assertEqual('Josh Stone', Parent.objects.latest('id').name)
    31623162        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

     
    391391    model = Parent
    392392    inlines = [ChildInline]
    393393
     394    list_editable = ('name',)
     395
    394396    def save_related(self, request, form, formsets, change):
    395397        super(ParentAdmin, self).save_related(request, form, formsets, change)
    396398        first_name, last_name = form.instance.name.split()
Back to Top