I added an action in my admin pages that allows user to export selected records to an excel sheet. Now I need to be able to only allow some users to be able to export data. I have a UserProfile
model that has a can_export
boolean field.
How can I only show the "Export To Excel" action in django admin only if they have the can_export
field set as True?
I have tried to find a way in admin.py to get the request object and do a IF statement before setting actions but have had no luck. I get a name'request' is not defined error of course.
if request.user.get_profile().can_export:
actions = [export_data()]