#29927 closed Bug (worksforme)
ModelAdmin.exclude ignored when generating readonly view
Reported by: | Ben Cole | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 2.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Fields added to a ModelAdmin.exclude
are not excluded when generating a "readonly" view as per the new functionality
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
Change History (3)
comment:1 by , 6 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:2 by , 6 years ago
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.
comment:3 by , 6 years ago
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?
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.