Search code examples
pythondjangodjango-grappelli

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


Solution

  • 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'