I've it done in admin list display by simple creating a function and adding it to list_display. I want something similar in detail view. Can this be done?
models.py
class Log(models.Model):
created = models.DateTimeField(null=True, auto_now_add=True)
model = models.CharField(max_length=100)
modified = models.DateTimeField(null=True, auto_now=True)
req_endpoint = models.CharField(max_length=800)
resp_json = models.TextField(max_length=1000)
resp_img_uri = models.CharField(max_length=750)
input_image = models.CharField(max_length=750)
status_code = models.CharField(max_length=100)
elapsed_time = models.CharField(max_length=100)
score = models.CharField(max_length=100)
request_domain = models.CharField(max_length=100)
human_observation = models.CharField(max_length=50, choices = confusion_matrix, editable=True)
def __str__(self):
return self.human_observation
admin.py
class LogAdmin(admin.ModelAdmin):
list_filter = ('model','human_observation')
list_display = ['id','response_img','input_img','model','score','created','human_observation','admin_image']
ordering = ['-id']
def response_img(self, obj):
return format_html('<img src="{0}" style=" object-fit: cover; width: auto;height: 60px;" />'.format(obj.resp_img_uri))
def input_img(self, obj):
return format_html('<img src="{0}" style=" object-fit: cover; width: auto;height: 60px;" />'.format(obj.input_image))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…