Shubham Devgan
Shubham Devgan

Reputation: 614

safe template tag in django admin

I am using django-grappelli as django admin template. But I want to use {{foo|safe}} for a particular entry from my database which I made using CKeditor, which is being displayed in admin template. I know how to use safe tag in templates but I don't to how to use them in admin site.I want to apply safe tag to Bio field .Thanks.

Screen shot of Feild

Upvotes: 0

Views: 991

Answers (1)

niekas
niekas

Reputation: 9107

You could define a new field, which would use mark_safe:

from django.utils.safestring import mark_safe

class ExampleModelAdmin(admin.ModelAdmin):
    base_model = ExampleModel
    list_display = (..., 'enter_bio_safe')

    def enter_bio_safe(self, obj):
        return mark_safe(obj.enter_bio)
    enter_bio_safe.short_description = 'Enter bio'

Upvotes: 2

Related Questions