Opened 7 years ago

Closed 6 years ago

Last modified 5 years ago

#11639 closed New feature (fixed)

Can't remove prepopulated fields from fieldset in ModelAdmin

Reported by: leanmeandonothingmachine Owned by: nobody
Component: contrib.admin Version: 1.3-beta
Severity: Normal Keywords: sprintnov13
Cc: Ben Spaulding Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'd like to propose that when the prepopulated fields argument that is passed to the AdminForm helper in BaseModelAdmin is generated by a method that takes the request object. That would give you ability to use the get_fieldsets overide to filter out prepopulated fields and then use this new override to alter the prepopulated fields to match what you did in get_fieldsets. See attached patch for my implementation.

Attachments (1)

pre_populated.diff (9.5 KB) - added by leanmeandonothingmachine 6 years ago.

Download all attachments as: .zip

Change History (19)

comment:1 Changed 7 years ago by leanmeandonothingmachine

Sorry that should be in ModelAdmin not BaseModelAdmin

comment:2 Changed 7 years ago by Alex Gaynor

Triage Stage: UnreviewedAccepted

comment:3 Changed 7 years ago by leanmeandonothingmachine

I updated the patch so it applies against trunk.

comment:4 Changed 6 years ago by leanmeandonothingmachine

milestone: 1.3
Version: 1.11.2

Updated the patch again. If there is anything wrong with this that is holding it up please lmk, i'd be happy to improve it.

comment:5 Changed 6 years ago by steph

Keywords: sprintnov13 added

comment:6 Changed 6 years ago by Ben Spaulding

Cc: Ben Spaulding added

comment:7 Changed 6 years ago by Julien Phalip

milestone: 1.31.4
Needs documentation: set
Needs tests: set

That's a useful feature, but unfortunately it is too late for 1.3.

Changed 6 years ago by leanmeandonothingmachine

Attachment: pre_populated.diff added

comment:8 Changed 6 years ago by leanmeandonothingmachine

milestone: 1.41.3
Version: 1.21.3-beta

I updated the patch to include tests and documentation. I also added inline support based on the way get_readonly_fields works. Can this be considered for 1.3? If it really is too late then change it back to 1.4, it would be nice though to have this get some attention.

comment:9 Changed 6 years ago by leanmeandonothingmachine

Needs documentation: unset
Needs tests: unset

comment:10 Changed 6 years ago by Julien Phalip

Triage Stage: AcceptedReady for checkin

This is a good patch, thanks for your great work. There's no guarantee that it can make it in 1.3 as this is essentially a new feature and we're now in beta stage. So we'll see ;)

comment:11 Changed 6 years ago by Russell Keith-Magee

milestone: 1.31.4

Agreed that this looks like a good idea, but it's definitely a new feature, not a bug fix, so it can't be added to 1.3 at this point.

comment:12 Changed 6 years ago by leanmeandonothingmachine

Ok, on the other hand it could be considered a fix for the bug in #13618

comment:13 Changed 6 years ago by Julien Phalip

Severity: Normal
Type: New feature

comment:14 Changed 6 years ago by defaultwombat

Easy pickings: unset

This is definitly a fix for #13618 too.

Additionally it solves a problem when trying to manually fix the #13618 issue by changeing the prepopulated_fields e.g. in the change_view.
As this is a dictionary shared over all instances of the Adminmodel, after altering it you lost the prepopulating feature until server refresh.

comment:15 Changed 6 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

In [16069]:

Fixed #11639, #13618 -- Added get_prepopulated_fields method to ModelAdmin and InlineModelAdmin to be able to handle prepopulated fields on a case-by-case basis. Thanks, leanmeandonothingmachine.

comment:16 Changed 5 years ago by Jacob

milestone: 1.4

Milestone 1.4 deleted

comment:17 Changed 5 years ago by hcarvalhoalves@…

UI/UX: unset

Any reason why this ticket didn't entered 1.3.1? It's still set for 1.3-beta. I would like to see this checked in for 1.3.2, let me know if I can help with tests or documentation. It's pretty annoying to have the get_fieldsets hook available but see it fail because of prepopulated_fields , and then rewrite almost half of the ModelAdmin to fix it.

comment:18 in reply to:  17 Changed 5 years ago by Ramiro Morales

Replying to hcarvalhoalves@…:

Any reason why this ticket didn't entered 1.3.1?

It's because bug fixes like this are no longer backported to the stable branch - it will not be in the next 1.3.X release. See https://docs.djangoproject.com/en/dev/internals/release-process/#supported-versions -- We changed our backporting policy for the maintenance period post 1.3.

It's still set for 1.3-beta

I was reported as present in 1.3 beta (Version field of this ticket) but it was targetted to be fixed in 1.4 (Milestone field, since then removed from our Trac installation)

I would like to see this checked in for 1.3.2, let me know if I can help with tests or documentation. It's pretty annoying to have the get_fieldsets hook available but see it fail because of prepopulated_fields , and then rewrite almost half of the ModelAdmin to fix it.

You can always port the changes committed to fix this ticket (or a subset of them) to a local copy of the 1.3.X branch and use that.

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