Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#20076 closed Uncategorized (worksforme)

Admin read-only fields should be included in POST

Reported by: jonash Owned by: nobody
Component: contrib.admin Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Fields marked readonly in the admin are not included in the POST in case the model is saved. Now if such field does not have @blank=True@, the form doesn't validate since a non-blank field is missing a value.

These values should be included in the form as hidden fields.

Change History (2)

comment:1 Changed 2 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

Fields listed in readonly_fields are excluded from the default model form build by the admin, therefore they do not need to be in POST in order for the form validation and model save to succeed, see https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#django.contrib.admin.ModelAdmin.readonly_fields. I just tried this and it works fine to edit-and-save a model with a readonly field (that already has a value in the field), there is something beyond a simple readonly field and default admin here that led to the assertion that values were needed in POST. Without knowing the specifics of the situation though, it's hard to guess whether there is a bug in Django or a mis-use/misconfiguation in the model admin using readonly_fields.

comment:2 Changed 2 years ago by jonash

Sorry. Seems to have been an issue with my code.

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