Opened 7 years ago

Closed 2 years 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 5 years ago.
Minimal project to reproduce issue

Download all attachments as: .zip

Change History (21)

comment:1 by Tim Graham, 7 years ago

Resolution: worksforme
Status: newclosed

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

comment:2 by Ryan Siemens, 5 years ago

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 inline, but any additional forms added via "Add another <Model>" will not run the js that pre populates the field.

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

Version 1, edited 5 years ago by Ryan Siemens (previous) (next) (diff)

by Ryan Siemens, 5 years ago

Attachment: prepopulated-issue.tar.gz added

Minimal project to reproduce issue

comment:3 by Ryan Siemens, 5 years ago

UI/UX: set

comment:4 by Simon Charette, 5 years ago

Triage Stage: UnreviewedAccepted

Thanks for the very detailed reproduction case Ryan.

comment:5 by Jakob Köhler, 5 years ago

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

comment:6 by Mariusz Felisiak, 5 years ago

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

comment:7 by Mariusz Felisiak, 5 years ago

Needs tests: set

comment:8 by Jakob Köhler, 4 years ago

Needs tests: unset

I added a test for the scenario defined by Ryan ✅

comment:9 by Mariusz Felisiak, 4 years ago

Patch needs improvement: set

comment:10 by David Smith, 3 years ago

Easy pickings: set

comment:11 by David Smith, 3 years ago

Owner: Jakob Köhler removed
Status: assignednew

comment:15 by Zoltán Szatmáry, 3 years ago

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 3 years ago by Zoltán Szatmáry (previous) (diff)

comment:16 by Mariusz Felisiak, 3 years ago

Needs tests: set

comment:17 by Shubh Parmar, 2 years ago

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 by Shubh Parmar, 2 years ago

Cc: Shubh Parmar added

comment:20 by Mariusz Felisiak, 2 years ago

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

comment:21 by Mariusz Felisiak, 2 years ago

Patch needs improvement: set

comment:22 by Mariusz Felisiak, 2 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:23 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

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