Re: [Django] #13659: Make the request accessible in callables used in ModelAdmin.list_display

14 views
Skip to first unread message

Django

unread,
Jun 20, 2016, 10:10:10 PM6/20/16
to django-...@googlegroups.com
#13659: Make the request accessible in callables used in ModelAdmin.list_display
---------------------------------+------------------------------------
Reporter: sebastian_noack | Owner: czpython
Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by czpython):

* owner: nobody => czpython
* status: new => assigned


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

Django

unread,
Jan 16, 2017, 4:55:58 AM1/16/17
to django-...@googlegroups.com
#13659: Make the request accessible in callables used in ModelAdmin.list_display
---------------------------------+------------------------------------
Reporter: Sebastian Noack | Owner: Paulo

Type: New feature | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Andreas Pelme):

* cc: andreas@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/13659#comment:12>

Django

unread,
Mar 25, 2021, 6:43:28 PM3/25/21
to django-...@googlegroups.com
#13659: Make the request accessible in callables used in ModelAdmin.list_display
---------------------------------+------------------------------------
Reporter: Sebastian Noack | Owner: Paulo
Type: New feature | Status: assigned
Component: contrib.admin | Version: dev

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by dbartenstein):

As callables in list_display don’t get the request object, is it safe to
add the request object as attribute to the admin class object? In the
callable it would then be possible to access the request via self.request
to e.g. check if the current user has permission to edit the object.

Code sample:
{{{
def changelist_view(self, request, extra_context=None):
self.request = request # Is it safe to store the request?
return super().changelist_view(request, extra_context)

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/13659#comment:13>

Django

unread,
Mar 25, 2021, 7:51:58 PM3/25/21
to django-...@googlegroups.com
#13659: Make the request accessible in callables used in ModelAdmin.list_display
---------------------------------+------------------------------------
Reporter: Sebastian Noack | Owner: Paulo
Type: New feature | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by Tim Graham):

No, storing state on the `ModelAdmin` class isn't thread-safe.

--
Ticket URL: <https://code.djangoproject.com/ticket/13659#comment:14>

Django

unread,
Mar 26, 2021, 5:38:06 AM3/26/21
to django-...@googlegroups.com
#13659: Make the request accessible in callables used in ModelAdmin.list_display
---------------------------------+------------------------------------
Reporter: Sebastian Noack | Owner: Paulo
Type: New feature | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by Dominik Bartenstein):

Replying to [comment:14 Tim Graham]:


> No, storing state on the `ModelAdmin` class isn't thread-safe.

Thanks a lot for the quick answer, Tim!

What approach do you recommend when the request object is to be considered
in a callable used with list_display?
There is middleware such as https://github.com/jedie/django-
tools/blob/master/django_tools/middlewares/ThreadLocal.py

Use case:
In the callable used with list_display the user’s permissions for each
object have to be checked. Thus we need access to request.user.

--
Ticket URL: <https://code.djangoproject.com/ticket/13659#comment:15>

Reply all
Reply to author
Forward
0 new messages