Django Admin list_display에 custom link 추가

2021. 2. 11. 20:50파이썬/Django

    list_display = ['id','linkImage',]

    def linkImage(self, obj) :
        url = reverse('admin:ocr_trained_image_change', args=[obj.image])
        return format_html("<a href='{}'>{}</a>",url,obj.image)
    linkImage.short_description = 'Image'
    list_display = ['id','popup_gantt','manager']

    def popup_gantt(self, obj) :
        return format_html("<a href='javascript:window.open(\"/gantt/gantt/{}\")'>{}</a>", obj.id,obj.name)