#29929 closed Bug (fixed)
ModelAdmin.prepopulated_fields crashing admin when showing read-only view
Reported by: | Sébastiaan Versteeg | Owned by: | Basil Dubyk |
---|---|---|---|
Component: | contrib.admin | Version: | 2.1 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The values of the ModelAdmin.prepopulated_fields
field will be used when showing a read-only view in the admin. This results in a KeyError
: "Key 'to_be_prepopulated' not found in 'SampleModelForm'. Choices are: ."
.
class SampleModel(models.Model): input_value = models.TextField() to_be_prepopulated = models.TextField()
@admin.register(SampleModel) class SampleModelAdmin(admin.ModelAdmin): prepopulated_fields = {'to_be_prepopulated': ('input_value',)} def has_change_permission(self, request, obj=None): return False
Attachments (1)
Change History (9)
comment:1 by , 6 years ago
by , 6 years ago
Attachment: | 0001-Tests-that-demonstrate-breakage.patch added |
---|
The attached file demonstrates the issue in the Django test suite.
comment:2 by , 6 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 6 years ago
Severity: | Normal → Release blocker |
---|
comment:4 by , 6 years ago
Would it suffice to filter all read-only fields from the prepopulated fields? That would also have the side effect that normal read-only fields are also allowed to be prepopulated though.
comment:5 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Note:
See TracTickets
for help on using tickets.
This was also noted at https://github.com/django/django/pull/6734#issuecomment-261015510