Opened 3 years ago

Last modified 8 months 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: no Patch needs improvement: yes
Easy pickings: no UI/UX: yes


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 17 months ago.
Minimal project to reproduce issue

Download all attachments as: .zip

Change History (10)

comment:1 Changed 3 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 17 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

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

Changed 17 months ago by Ryan Siemens

Attachment: prepopulated-issue.tar.gz added

Minimal project to reproduce issue

comment:3 Changed 17 months ago by Ryan Siemens

UI/UX: set

comment:4 Changed 17 months ago by Simon Charette

Triage Stage: UnreviewedAccepted

Thanks for the very detailed reproduction case Ryan.

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

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

comment:6 Changed 13 months 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 13 months ago by felixxm

Needs tests: set

comment:8 Changed 9 months ago by Jakob Köhler

Needs tests: unset

I added a test for the scenario defined by Ryan ✅

comment:9 Changed 8 months ago by felixxm

Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top