Opened 10 years ago

Last modified 9 years ago

#14938 closed

"Save as" does not save entries added with a TabularInline — at Version 4

Reported by: rax Owned by: nobody
Component: Forms Version: 1.2-beta
Severity: Keywords: save-as
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by Ramiro Morales)

What steps will reproduce the problem?

  1. go to the admin change form of an instance of a model class with both the "save as" feature enabled, and a TabularInline for relate items.
  2. change the original instance
  3. add a new related instance using the TabularInline

What is the expected output? What do you see instead?

A new instance should be created, a copy of all the related instances should be created and a new instance for any item added in the TabularInline should be created.
Instead the original item is created, all the pre-existing instances are copied but the new ones are not created.

Note: deleting an entry works as expected is just the add that "fails" by creating the new instance without adding the new related items.

Additional information

django version: 1.2.3
locale: it-IT

this may also be related to #4045

Change History (5)

Changed 10 years ago by rax

Attachment: 14938_patch.txt added

Patch fixing the issue

comment:1 Changed 10 years ago by rax

Has patch: set
Needs tests: set

The "save as" button in the admin change form simply redirects to the add_view with the only difference that the "save_as_new" parameter is passed to the formset:

formset = FormSet(data=request.POST, files=request.FILES,
         prefix=prefix, queryset=inline.queryset(request))

Where "FormSet" are instances of "BaseInlineFormSet"

It's a problem in the BaseInlineFormSet class. See the attached patch.

comment:2 Changed 10 years ago by Julien Phalip

milestone: 1.3
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Yes, I could verify this issue. Here's a simple test case:


from django.db import models

class Foo(models.Model):
    name = models.CharField(max_length=30)

class Bar(models.Model):
    parent = models.ForeignKey(Foo)
    title = models.CharField(max_length=30)


from django.contrib import admin
from .models import Foo, Bar

class BarInline(admin.StackedInline):
    model = Bar

class FooAdmin(admin.ModelAdmin):
    inlines = (BarInline,)
    save_as = True, FooAdmin)

New inlines added before clicking "Save as new" get lost.

I really doubt your patch is the way to go , though.

comment:3 Changed 10 years ago by Julien Phalip

#14949 was closed as dupe.

comment:4 Changed 10 years ago by Ramiro Morales

Description: modified (diff)

(reformatted description)

Note: See TracTickets for help on using tickets.
Back to Top