readonly_fields doesn't work with fields not part of the model
|Reported by:||benc||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
using readonly_fields in the admin works for fields of the model
but when I add a field to the form and try to make it readonly I'm getting an error:
ImproperlyConfigured at /admin/myapp/mymodel/1/ MyModelAdmin.readonly_fields, 'somefield' is not a callable or an attribute of 'MyModelAdmin' or found in the model 'MyModel'.
readonly_fields is useful to show calculated fields.
I'm using it to show the sum of inline cart items.
class MyModelAdminForm(forms.ModelForm): class Meta: model = MyModel somefield = forms.CharField() class MyModelAdmin(admin.ModelAdmin): form = MyModelAdminForm readonly_fields = ('somefield',)
Change History (4)
comment:1 Changed 4 years ago by russellm
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Resolution set to wontfix
- Status changed from new to closed
comment:2 Changed 4 years ago by benc
- Resolution wontfix deleted
- Status changed from closed to reopened
comment:3 Changed 4 years ago by russellm
- Resolution set to worksforme
- Status changed from reopened to closed