1๐
โ
I may have found the answer. Instead of specifying the fieldsets
variable at the beginning of the class, I can define the get_fieldsets
method, in this way:
admin.py
class ItemOrderAdmin(admin.ModelAdmin):
...
readonly_fields = [..., 'created', 'modified', 'refund_link']
[other functions]
def get_fieldsets(self, request, obj=None):
fieldsets = [
...
('Actions', {'fields': ['created', 'modified', 'refund_link']}),
]
if request.user.is_superuser:
fieldsets[4][1]['fields'].append('refund_link') # The 4 depends on the fieldsets structure.
return fieldsets
def refund_link(self, order):
...
Iโll wait a few hours before approving my answer, in case someone comes up with a better solution, or there are major flaws in mine.
๐คGRB
Source:stackexchange.com