Code

Opened 5 years ago

Closed 3 years ago

Last modified 2 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: benspaulding 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 3 years ago.

Download all attachments as: .zip

Change History (19)

comment:1 Changed 5 years ago by leanmeandonothingmachine

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Sorry that should be in ModelAdmin not BaseModelAdmin

comment:2 Changed 5 years ago by Alex

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 5 years ago by leanmeandonothingmachine

I updated the patch so it applies against trunk.

comment:4 Changed 4 years ago by leanmeandonothingmachine

  • milestone set to 1.3
  • Version changed from 1.1 to 1.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 3 years ago by steph

  • Keywords sprintnov13 added

comment:6 Changed 3 years ago by benspaulding

  • Cc benspaulding added

comment:7 Changed 3 years ago by julien

  • milestone changed from 1.3 to 1.4
  • Needs documentation set
  • Needs tests set

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

Changed 3 years ago by leanmeandonothingmachine

comment:8 Changed 3 years ago by leanmeandonothingmachine

  • milestone changed from 1.4 to 1.3
  • Version changed from 1.2 to 1.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 3 years ago by leanmeandonothingmachine

  • Needs documentation unset
  • Needs tests unset

comment:10 Changed 3 years ago by julien

  • Triage Stage changed from Accepted to Ready 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 3 years ago by russellm

  • milestone changed from 1.3 to 1.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 3 years ago by leanmeandonothingmachine

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

comment:13 Changed 3 years ago by julien

  • Severity set to Normal
  • Type set to New feature

comment:14 Changed 3 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 3 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

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 3 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

comment:17 follow-up: Changed 2 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 2 years ago by ramiro

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.