* 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.
* cc: andreas@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/13659#comment:12>
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>
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>
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>