> Is is possible to render unescaped HTML in admin pages?
> 
> (say) A model has a field "text" which contains HTML markup. Is this
> something that can be changed on the model (ie __unicode__ method) or
> do I have to change the admin templates?

If you're only going to render html for lists it's possible to add an
'allow_tags' attribute to a field to be added to list_display:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display


In order to display RAW html inside the admin change view you have lots
of choices.

(a) either write a custom field that returns a different widget
http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#formfield

(b) or use a standard field and specify formfield_overrides
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_overrides

(c) or use a custom form
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.form

(d) or just provide a custom template
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.change_form_template


I'd probably go for (a) as it looks the cleanest to me and is reusable.
A HTMLMarkupField could also provide methods like verify(), tidy(), etc.
(b) is a good choice if you generally want to change the way all Char-
and TextFields behave. (c) and (d) provide the most flexibility, while
coming at the cost of being quite verbose.


--mp

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to