Opened 6 years ago

Closed 16 months ago

#28357 closed Bug (fixed)

Prepopulated_fields doesn't work for admin.StackedInline.

Reported by: ChristosKon Owned by: Shubh Parmar
Component: contrib.admin Version: dev
Severity: Normal Keywords: admin, stackedinline, prepopulated_fields
Cc: Ryan Siemens, Zoltán Szatmáry, Shubh Parmar Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no 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 4 years ago.
Minimal project to reproduce issue

Download all attachments as: .zip

Change History (21)

comment:1 Changed 6 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 4 years 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 4 years ago by Ryan Siemens (previous) (diff)

Changed 4 years ago by Ryan Siemens

Attachment: prepopulated-issue.tar.gz added

Minimal project to reproduce issue

comment:3 Changed 4 years ago by Ryan Siemens

UI/UX: set

comment:4 Changed 4 years ago by Simon Charette

Triage Stage: UnreviewedAccepted

Thanks for the very detailed reproduction case Ryan.

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

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

comment:6 Changed 4 years ago by Mariusz Felisiak

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 4 years ago by Mariusz Felisiak

Needs tests: set

comment:8 Changed 3 years ago by Jakob Köhler

Needs tests: unset

I added a test for the scenario defined by Ryan ✅

comment:9 Changed 3 years ago by Mariusz Felisiak

Patch needs improvement: set

comment:10 Changed 2 years ago by David Smith

Easy pickings: set

comment:11 Changed 20 months ago by David Smith

Owner: Jakob Köhler deleted
Status: assignednew

comment:15 Changed 18 months ago by Zoltán Szatmáry

Cc: Zoltán Szatmáry added
Owner: set to Zoltán Szatmáry

Yesterday I made a PR for this one. https://github.com/django/django/pull/14967
It only required changes in the inlines.js file.

Last edited 18 months ago by Zoltán Szatmáry (previous) (diff)

comment:16 Changed 18 months ago by Mariusz Felisiak

Needs tests: set

comment:17 Changed 16 months ago by Shubh Parmar

Owner: changed from Zoltán Szatmáry to Shubh Parmar

Since there is no updates regarding this ticket for weeks, I want to work on it.

comment:18 Changed 16 months ago by Shubh Parmar

Cc: Shubh Parmar added

comment:20 Changed 16 months ago by Mariusz Felisiak

Easy pickings: unset
Needs tests: unset
Patch needs improvement: unset
Status: newassigned

comment:21 Changed 16 months ago by Mariusz Felisiak

Patch needs improvement: set

comment:22 Changed 16 months ago by Mariusz Felisiak

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:23 Changed 16 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In bb223c6:

Fixed #28357 -- Fixed ModelAdmin.prepopulated_fields on newly added stacked inline.

Thanks Jakob Köhler for the initial patch.

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