Opened 2 years ago

Last modified 6 weeks ago

#28357 assigned Bug

Prepopulated_fields doesn't work for admin.StackedInline.

Reported by: ChristosKon Owned by: Jakob Köhler
Component: contrib.admin Version: master
Severity: Normal Keywords: admin, stackedinline, prepopulated_fields
Cc: Ryan Siemens Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

I think that I found a bug (new to Django)

Prepopulated_fields doesn't work for StackedInline class while it works fine for TabularInline class.

Please let me know if you need any more information.

Attachments (1)

prepopulated-issue.tar.gz (3.0 KB) - added by Ryan Siemens 5 months ago.
Minimal project to reproduce issue

Download all attachments as: .zip

Change History (8)

comment:1 Changed 2 years ago by Tim Graham

Resolution: worksforme
Status: newclosed

I tested with a a simple project and couldn't reproduce a problem. Please provide more details.

comment:2 Changed 5 months ago by Ryan Siemens

Cc: Ryan Siemens added
Resolution: worksforme
Status: closednew
Version: 1.112.1

Reopening as I ran into this issue (at least similar) today. Some additional info:

The prepopulated_fields will work for the extra forms specified, in the admin.StackedInline, but any additional forms added via "Add another <Model>" will not run the js that pre populates the field. admin.TabularInline seems to work fine and is unaffected by this.

class ArticleInline(admin.StackedInline):
    model = Article
    extra = 2
    # will only prepopulate the ``slug`` field for the 2 ``extra`` forms
    # in the formset
    prepopulated_fields = {"slug": ("title",)}

Verified this issue is happening in 2.1 and 1.11 and attached a minimal project that reproduces the issue.

To reproduce:

  1. extract the attached project
  2. run the migrations
  3. create a superuser
  4. navigate to admin/myapp/blog/add/
  5. adding a title to extra forms in the the stacked inline articles prepopulates the slug field
  6. click "Add another Article"
  7. ASSERT adding a title the newly added stacked inline article form does not prepopulate the slug field

Here is a screen grab showing the results of steps 5-7 https://zappy.zapier.com/22F716E5-1D64-4763-B731-DE62D24F8FC0.mp4

Last edited 5 months ago by Ryan Siemens (previous) (diff)

Changed 5 months ago by Ryan Siemens

Attachment: prepopulated-issue.tar.gz added

Minimal project to reproduce issue

comment:3 Changed 5 months ago by Ryan Siemens

UI/UX: set

comment:4 Changed 5 months ago by Simon Charette

Triage Stage: UnreviewedAccepted

Thanks for the very detailed reproduction case Ryan.

comment:5 Changed 4 months ago by Jakob Köhler

Owner: changed from nobody to Jakob Köhler
Status: newassigned

comment:6 Changed 6 weeks ago by felixxm

Has patch: set
Summary: Prepopulated_fields doesn't work for admin.StackedInlinePrepopulated_fields doesn't work for admin.StackedInline.
Version: 2.1master

comment:7 Changed 6 weeks ago by felixxm

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