readonly fields for admin
|Reported by:||Owned by:||nobody|
|Cc:||cscott@…, tom@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
This patch adds a readonly_fields attribute to the ModelAdmin class. Fields included in the list can be set in the add form but not in the change form. They will be displayed as text in the change form. It works as follows:
class TestModel(models.Model): dummy = models.CharField(maxlength=10) class TestAdmin(admin.ModelAdmin): readonly_fields = ('dummy',)
This feature is purely admin-side and does not interact with the editable=False option. Fields marked with editable=False will not be displayed at all and they will not be part of the django.newform.forms (ie the behavior of editable is left untouched).
How is it implemented:
If a field is in the readonly list, its widget will be set to DisplayWidget, which only prints the value (ie no <input> tag).
Currently this might not work for all type of fields because I'm awaiting confirmation on the design and API. Once the devs are ok, I will extend the patch to work with all fields.
note: this ticket is similar to #1714 in functionality but only modifies the admin side. Forms are not patched.
Change History (14)
comment:6 Changed 10 years ago by
|Patch needs improvement:||set|
|Triage Stage:||Design decision needed → Accepted|