[Django] #29927: ModelAdmin.exclude ignored when generating readonly view

4 views
Skip to first unread message

Django

unread,
Nov 7, 2018, 5:10:33 AM11/7/18
to django-...@googlegroups.com
#29927: ModelAdmin.exclude ignored when generating readonly view
-----------------------------------------+------------------------
Reporter: Ben Cole | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
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

--
Ticket URL: <https://code.djangoproject.com/ticket/29927>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 8, 2018, 5:07:59 AM11/8/18
to django-...@googlegroups.com
#29927: ModelAdmin.exclude ignored when generating readonly view
-------------------------------+--------------------------------------

Reporter: Ben Cole | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.1
Severity: Normal | Resolution: worksforme

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Carlton Gibson):

* 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>

Django

unread,
Nov 13, 2018, 12:01:45 PM11/13/18
to django-...@googlegroups.com
#29927: ModelAdmin.exclude ignored when generating readonly view
-------------------------------+--------------------------------------

Reporter: Ben Cole | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.1
Severity: Normal | Resolution: worksforme

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

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>

Django

unread,
Nov 14, 2018, 3:57:49 AM11/14/18
to django-...@googlegroups.com
#29927: ModelAdmin.exclude ignored when generating readonly view
-------------------------------+--------------------------------------

Reporter: Ben Cole | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.1
Severity: Normal | Resolution: worksforme

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages