Ticket #4507: newforms-admin-form-save-hooks.diff

File newforms-admin-form-save-hooks.diff, 1.9 KB (added by Stas Shtin <antisvin@…>, 8 years ago)
  • django/contrib/admin/options.py

     
    292292        """
    293293        return self.queryset(request)
    294294
     295    def form_save(self, request, form):
     296        """
     297        Returns object saved from curent form.
     298        """
     299        return form.save(commit=True)
     300
     301    def form_save_add(self, request, form):
     302        """
     303        Returns object saved from current form in add stage.
     304        """
     305        return self.form_save(form, request)
     306
     307    def form_save_change(self, request, form):
     308        """
     309        Returns object saved from current form in change stage.
     310        """
     311        return self.form_save(form, request)
     312
    295313    def save_add(self, request, model, form, post_url_continue):
    296314        """
    297315        Saves the object in the "add" stage and returns an HttpResponseRedirect.
     
    301319        from django.contrib.admin.models import LogEntry, ADDITION
    302320        from django.contrib.contenttypes.models import ContentType
    303321        opts = model._meta
    304         new_object = form.save(commit=True)
     322        new_object = self.form_save_add(request, form)
    305323        pk_value = new_object._get_pk_val()
    306324        LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, str(new_object), ADDITION)
    307325        msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': opts.verbose_name, 'obj': new_object}
     
    340358        from django.contrib.admin.models import LogEntry, CHANGE
    341359        from django.contrib.contenttypes.models import ContentType
    342360        opts = model._meta
    343         new_object = form.save(commit=True)
     361        new_object = self.form_save_change(request, form)
    344362        pk_value = new_object._get_pk_val()
    345363
    346364        # Construct the change message. TODO: Temporarily commented-out,
Back to Top