Reputation: 8846
My problem here is, In django admin list view the action checkboxes are not being displayed when I use changelist_view
in admin. I have given the admin.py
code below. Please go through it and provide me a solution.
def changelist_view(self, request, extra_context=None):
if request.user == 'admin':
self.list_display_links = ('project', )
self.list_display = ('project', 'task_name', 'assignee_role', 'assignee_name', )
else:
self.list_display_links = ('task_name', )
self.list_display = ( 'task_name', 'project', 'priority', )
return super(ModelAdmin, self).changelist_view(request, extra_context = None)
Here what I want to achieve is to change the list_display
and list_display_links
fields based on user. I'm achieving it when I use changelist_view
. But the action checkboxes are being hidden for all users when I do this.
So how to display action checkboxes when using changelist_view
or how to achieve the above things without using changelist_view
. Please provide a solution.
Upvotes: 2
Views: 2118
Reputation: 8846
I found a solution after going through the django installation source file django/contrib/admin/options.py
. To display action checkbox when using changelist_view
include it in list_display
. But I couldn't figure out why it is being hidden when using changelist_view
.
def changelist_view(self, request, extra_context=None):
if request.user == 'admin':
self.list_display_links = ('project', )
self.list_display = ('action_checkbox', 'project', 'task_name', 'assignee_role', 'assignee_name', )
else:
self.list_display_links = ('task_name', )
self.list_display = ( 'task_name', 'project', 'priority', )
return super(ModelAdmin, self).changelist_view(request, extra_context = None)
So here the action checkbox will be displayed only if the current logged in user is admin since it is included in list_display
.
Upvotes: 4