可能重复:
Override django-admin edit form field values for encrypted data
内联模型有加密数据,我需要覆盖渲染admin.TabularInline中每个字段来解密数据的方法。
答案 0 :(得分:4)
您可以向TabularInline
添加功能,然后将其显示为字段:
class MyTabularInline(admin.TabularInline):
model = MyModel
readonly_fields = ['decrypt_first_field', 'decrypt_second_field']
def decrypt_first_field(self, obj):
if obj.first_field:
return decrypt(obj.first_field)
else:
return 'Nothing here ...'
def decrypt_first_field(self, obj):
...