Opened 18 years ago
Closed 16 years ago
#3990 closed (duplicate)
readonly fields for admin
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Keywords: | nfa-someday | |
Cc: | cscott@…, tom@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
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.
Attachments (3)
Change History (14)
by , 18 years ago
Attachment: | admin_readonly_fields_v1.patch added |
---|
by , 18 years ago
Attachment: | admin_readonly_fields_v1.diff added |
---|
comment:1 by , 18 years ago
comment:4 by , 18 years ago
by , 18 years ago
Attachment: | admin_readonly_fields_v1.1.diff added |
---|
comment:5 by , 18 years ago
The patch now supports all date/time fields and ForeignKey. I still need to work on ManyToMany fields.
comment:6 by , 18 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Design decision needed → Accepted |
Fields that are not editable are the readonly fields. We don't need an extra attribute for that.
Also, both empty and NULL fields should just display as the empty string (i.e. not at all). The difference isn't important for a read only field -- it's not like you can change it.
This looks like a reasonable idea, but it's over-engineered at the moment. It should also be usable for all forms, not just the admin interface.
comment:7 by , 18 years ago
Version: | new-admin → SVN |
---|
comment:8 by , 17 years ago
Cc: | added |
---|
An attribute of this sort is badly needed: I have a few foreign key objects which reference tens of thousands of possible objects. Generating a select widget for this field kills the server and browser, but I'd still like to see its current value when I'm browsing data.
I disagree with mtredinnick that 'editable' should be overloaded for 'readonly'. There are two separate concepts here, although calling them 'hidden' and 'editable' would be a reasonable solution.
comment:9 by , 17 years ago
Keywords: | nfa-someday added |
---|
The behavior of editable
is not going to change. This can be accomplish by writing your own widget that makes a text input box readonly or just display the value and have a hidden input box. newforms-admin gives you the ability to override any database field's formfield and/or widget. In all honesty this should be closed once newforms-admin is merged, but it might be a better case to write a patch that includes this widget in newforms-admin.
comment:11 by , 16 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Duplicate of #342 , albeit a little different.
sorry for the mix up, the first patch is no good.