Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

django - How do I display image in an object detail view without creating an extra ImageField?

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))



与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...