python - How to get logged in user modelAdmin callable in django -


i have this:

class summaryadmin(admin.modeladmin):     list_display = ('date', 'display_user', 'from_till', 'hours_worked',                     'productivity_status',)     list_filter = ['date', 'user_crm']      def display_user(self, obj):         test = "unknown"         temp = obj.user_crm          #if user.has_perm('crm.list_all_customers'):         if temp.user:             first_name = temp.user.first_name             last_name = temp.user.last_name             test = "%s %s" % (first_name, last_name)         elif temp.alternate:             test = "%s " % temp.alternate         else:             test = "%s (not linked)" % obj.user          #return obj.salesperson if obj.salesperson not none else ''         return test 

is possible logged in user while in display_user function?

i think need use threadlocals store request object, not readily available in django @ place need it.

try this:
https://github.com/nebstrebor/django-threadlocals

from threadlocals.threadlocals import get_current_user  class summaryadmin(admin.modeladmin):     list_display = ('date', 'display_user', 'from_till', 'hours_worked',                     'productivity_status',)     list_filter = ['date', 'user_crm']      def display_user(self, obj):        current_user = get_current_user()        ... 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -