0

I have a field that contains markdown. When I display it in my templates I can just put in {{activity.activity_notes|markdown}} to get it to format correctly. When it shows up in the Django admin, though, it is unfiltered and doesn't look nice.

I wrote a custom function to return compiled markdown, but when outputting it in Django admin it shows the literal html, tags and all. Is there a way I can set the output filter for a field in the Django admin interface?

4

1 回答 1

2

只需将get_markedown_activity_notes方法添加到您的模型并在管理员中使用list_display 该方法将如下所示

from django.contrib.markup.templatetags import markdown

class Activity(models.Model):
    ...
    def get_markedown_activity_notes(self):
        return markdown(self.activity_notes)

#in admin.py

class ActivityAdmin(admin.ModelAdmin):
      list_display = ('id','get_markedown_activity_notes',)

有关更多用例,请参阅文档

于 2013-04-23T20:15:18.893 回答