How can I return a HTML Tag, which will be interpreted, in a function in Django 1.4?
class MyModel(models.Model):
my_attribute = models.CharField(max_length=50)
def my_link(self):
return '<a href=google.com>google</a>'
Imagine I have this Model with the method my_link. In my Admin interface I want to display the columns my_attribute
and my_link
. But the problem is, that the html-Tag won't be interpreted. It just prints the text.
Since Django 1.5 there is the method format_html()
in the module django.utils.html
. But I need something similar in Django 1.4
EDIT
myapp.admin.py
from django.contrib import admin
from myapp.models import MyModel
class MyModelAdmin(admin.ModelAdmin):
list_display = ['my_attribute', 'my_link']
admin.site.register(MyModel, MyModelAdmin)