{{{
Class MyModel(models.Model):
field_to_show = models.TextField(default='foo')
field_to_exclude = models.TextField(default='should be hidden')
}}}
{{{
@admin.register(MyModel)
Class MyModelAdmin(admin.ModelAdmin):
exclude = ('field_to_exclude',)
def has_change_permission(self, request, obj=None):
return False
}}}
In the above example the `field_to_exclude` will be rendered on the
"readonly" change view
--
Ticket URL: <https://code.djangoproject.com/ticket/29927>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => worksforme
Comment:
Hi Ben,
I can't reproduce this in my test project:
I have an admin + a view-only user for that admin. All fields are shown as
read-only. I add one field to `exclude`. It is no-longer shown.
That's what I'm expecting.
Can you perhaps provide a test project with your exact setup, as there's
obviously some difference. (Or even better add a test case to the test
suite showing the bad behaviour if that's possible.)
Happy to re-open if we can reproduce.
Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/29927#comment:1>
Comment (by Ben Cole):
Turns out this occurred due to the field being in both `exclude` and
`readonly_fields`. In other situations (a field specified in two places)
this throws an error.
--
Ticket URL: <https://code.djangoproject.com/ticket/29927#comment:2>
Comment (by Carlton Gibson):
Hi Ben,
Thanks for the follow-up.
It might be possible to add a system check for that situation, if it
really doesn't make sense (which at first glance it doesn't). Is your
thought that you would want an error here? If so do you have capacity to
add a system check do you think?
--
Ticket URL: <https://code.djangoproject.com/ticket/29927#comment:3>