#13233: readonly_fields doesn't work with fields not part of the model
-------------------------------------+-------------------------------------
Reporter: benc | Owner: nobody
Type: Uncategorized | Status: closed
Component: contrib.admin | Version: 1.2-beta
Severity: Normal | Resolution:
| worksforme
Keywords: admin, | Triage Stage:
readonly_fields | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Mateusz Kurowski:
Old description:
> 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[0], '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',)
> }}}
>
> Thanks
New description:
Fields declared on form are not picked by admin model. Should they?
{{{
self.check(display_num_errors=True)
File "...\django\core\management\base.py", line 441, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System
check identified some issues:
ERRORS:
<class 'myapp.admin.MyModelAdmin'>: (admin.E035) The value of
'readonly_fields[4]' is not a callable, an attribute of 'MyModelAdmin', or
an attribute of 'awsapi.MyModel'.
<class 'myapp.admin.MyModelAdmin''>: (admin.E035) The value of
'readonly_fields[5]' is not a callable, an attribute of 'MyModelAdmin', or
an attribute of 'awsapi.MyModel'.
<class 'myapp.admin.MyModelAdmin''>: (admin.E035) The value of
'readonly_fields[6]' is not a callable, an attribute of 'MyModelAdmin', or
an attribute of 'awsapi.MyModel'.
System check identified 3 issues (0 silenced).
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/13233#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/062.7036fa2a25d6bc03cefbe75b1b0d5ca7%40djangoproject.com.