Ticket #8005: 8005.1.diff

File 8005.1.diff, 2.9 KB (added by simon, 16 years ago)
  • django/contrib/admin/options.py

     
    324324    def get_formsets(self, request, obj=None):
    325325        for inline in self.inline_instances:
    326326            yield inline.get_formset(request, obj)
    327 
     327   
     328    def save_model_add(self, request, form, formsets):
     329        new_object = form.save(commit=True)
     330       
     331        if formsets:
     332            for formset in formsets:
     333                # HACK: it seems like the parent obejct should be passed into
     334                # a method of something, not just set as an attribute
     335                formset.instance = new_object
     336                formset.save()
     337       
     338        return new_object
     339   
    328340    def save_add(self, request, form, formsets, post_url_continue):
    329341        """
    330342        Saves the object in the "add" stage and returns an HttpResponseRedirect.
     
    333345        """
    334346        from django.contrib.admin.models import LogEntry, ADDITION
    335347        opts = self.model._meta
    336         new_object = form.save(commit=True)
    337 
    338         if formsets:
    339             for formset in formsets:
    340                 # HACK: it seems like the parent obejct should be passed into
    341                 # a method of something, not just set as an attribute
    342                 formset.instance = new_object
    343                 formset.save()
    344 
     348       
     349        new_object = self.save_model_add(request, form, formsets)
     350       
    345351        pk_value = new_object._get_pk_val()
    346352        LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(self.model).id, pk_value, force_unicode(new_object), ADDITION)
    347353        msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': opts.verbose_name, 'obj': new_object}
     
    371377                post_url = '../../../'
    372378            return HttpResponseRedirect(post_url)
    373379    save_add = transaction.commit_on_success(save_add)
    374 
     380   
     381    def save_model_change(self, request, form, formsets):
     382        new_object = form.save(commit=True)
     383       
     384        if formsets:
     385            for formset in formsets:
     386                formset.save()
     387       
     388        return new_object
     389   
    375390    def save_change(self, request, form, formsets=None):
    376391        """
    377392        Saves the object in the "change" stage and returns an HttpResponseRedirect.
     
    382397        """
    383398        from django.contrib.admin.models import LogEntry, CHANGE
    384399        opts = self.model._meta
    385         new_object = form.save(commit=True)
     400       
     401        new_object = self.save_model_change(request, form, formsets)
     402       
    386403        pk_value = new_object._get_pk_val()
    387 
    388         if formsets:
    389             for formset in formsets:
    390                 formset.save()
    391 
     404       
    392405        # Construct the change message.
    393406        change_message = []
    394407        if form.changed_data:
Back to Top