Ticket #16115: new_hook_save_model_and_relations.diff

File new_hook_save_model_and_relations.diff, 2.2 KB (added by Igor Sobreira, 13 years ago)
  • django/contrib/admin/options.py

     
    683683        """
    684684        formset.save()
    685685
     686    def save_model_and_relations(self, request, obj, form, formsets, change):
     687        """
     688        Given a model instance, a bound form and a list of inline formsets
     689        save everything in to the database.
     690
     691        At this point save_form() has already been called, so just
     692        form.save_m2m() needs to be called.
     693        """
     694        self.save_model(request, new_object, form, change=change)
     695        form.save_m2m()
     696        for formset in formsets:
     697            self.save_formset(request, form, formset, change=change)
     698
    686699    def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
    687700        opts = self.model._meta
    688701        app_label = opts.app_label
     
    886899                                  prefix=prefix, queryset=inline.queryset(request))
    887900                formsets.append(formset)
    888901            if all_valid(formsets) and form_validated:
    889                 self.save_model(request, new_object, form, change=False)
    890                 form.save_m2m()
    891                 for formset in formsets:
    892                     self.save_formset(request, form, formset, change=False)
     902                self.save_model_and_relations(request, new_object, form, formset, change=False)
    893903
    894904                self.log_addition(request, new_object)
    895905                return self.response_add(request, new_object)
     
    988998                formsets.append(formset)
    989999
    9901000            if all_valid(formsets) and form_validated:
    991                 self.save_model(request, new_object, form, change=True)
    992                 form.save_m2m()
    993                 for formset in formsets:
    994                     self.save_formset(request, form, formset, change=True)
     1001                self.save_model_and_relations(request, new_object, form, formset, change=True)
    9951002
    9961003                change_message = self.construct_change_message(request, form, formsets)
    9971004                self.log_change(request, new_object, change_message)
Back to Top