admin list에서 함수의 결과를 나오게 하는 방법

2021. 1. 14. 23:35파이썬/Django

	
list_display = ['sentence_html','meaning_html', 'google_html']
search_fields = ['sentence','meaning']

    def sentence_html(self,obj) :
        return format_html(obj.sentence.replace('\n','<br>'))

    def meaning_html(self,obj) :
        return format_html(obj.meaning.replace('\n','<br>'))

    def google_html(self,obj) :
        if obj.google == None :
            return obj.google
        else :
            return format_html(obj.google.replace('\n','<br>'))

함수 라벨(label) 변경

    sentence_html.short_description = 'sentence'
    meaning_html.short_description = 'meaning'
    google_html.short_description = 'google'