I have the following code for the model and admin. The question column contains HTML content such as URL and image tags. However the admin still shows the raw HTML content and not formatted content. The model and the admin code is below:
Model
class question(models.Model):
question_id = models.AutoField(primary_key=True) # Unique ID
question = models.TextField() # HTML Content for the question
Admin
class QuestionAdmin(admin.ModelAdmin):
list_display = ('question_id','formatqn')
list_per_page = 10
def formatqn(self, obj):
return u'%s' % obj.question
formatqn.allow_tags = True
admin.site.register(question, QuestionAdmin)
Is that your code exactly? You have formatqn.allow_tags=True
indented inside the def formatqn
method after the return so it won't execute never, try to write the model with that line unindented like this:
class QuestionAdmin(admin.ModelAdmin):
list_display = ('question_id','formatqn')
list_per_page = 10
def formatqn(self, obj):
return u'%s' % obj.question
# this line unindented
formatqn.allow_tags = True
admin.site.register(question, QuestionAdmin)
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With