# HTML and JSON fields formatting in Admin's ModelForm

**URL:** <https://forum.djangoproject.com/t/html-and-json-fields-formatting-in-admins-modelform/27690>\
**Category:** The Admin\
**Created:** [February 2, 2024, 2:25pm UTC](https://forum.djangoproject.com/t/html-and-json-fields-formatting-in-admins-modelform/27690 "2024-02-02T14:25:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tortue-codage](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tortue-codage/32/18911_2.png) [@tortue-codage](https://forum.djangoproject.com/u/tortue-codage)\
**Post date:** [February 2, 2024, 2:25pm UTC](https://forum.djangoproject.com/t/html-and-json-fields-formatting-in-admins-modelform/27690/1 "2024-02-02T14:25:36Z")

</div>

Hey everyone!

I’m planning to apply **indentation** and **syntax highlighting** for the two mentioned fields’ contents of a model in my App’s Admin UI. Both of the fields should remain read-only.

I was thinking of extending the default admin’s template(s), or trying to handle my case using custom ModelForm with widgets or third party packages.

What’s the best approach to have the desired results?

Thanks!  
Cheers

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 2, 2024, 2:40pm UTC](https://forum.djangoproject.com/t/html-and-json-fields-formatting-in-admins-modelform/27690/2 "2024-02-02T14:40:38Z")

</div>

I don’t know about “best”, but if I had to approach something like this, I’d first try using the `readonly_fields` with a custom ModelAdmin method to format the contents of those fields. (This also means that I would _not_ include the original fields in that ModelAdmin class.)

See the third paragraph of the docs and example at [ModelAdmin.readonly\_fields](https://docs.djangoproject.com/en/5.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.readonly_fields).

This is only practical if you have a reasonable number of models and fields where you need to do this. If you’ve got a large number of models and fields, I’d be looking at a “higher level” solution by creating a custom ModelAdmin subclass to handle this parametrically, and then have my model admin classes inherit from _it_.

---

<div class="post-metadata">

**Author:** ![tortue-codage](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tortue-codage/32/18911_2.png) [@tortue-codage](https://forum.djangoproject.com/u/tortue-codage)\
**Post date:** [February 2, 2024, 2:52pm UTC](https://forum.djangoproject.com/t/html-and-json-fields-formatting-in-admins-modelform/27690/3 "2024-02-02T14:52:03Z")

</div>

Thanks @KenWhitesell!

I’m focusing only on the two fields of a single Model. Replacing the original fields with their customised “siblings” sounds great. The indentation part could be easily handled for both HTML and JSON fields. So the simplest solution for syntax highlighting of the given fields seems to be usage of some third party app, covering my custom fields.

---

<div class="post-metadata">

**Author:** ![nemesifier](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/nemesifier/32/29281_2.png) [@nemesifier](https://forum.djangoproject.com/u/nemesifier)\
**Post date:** [June 6, 2026, 6:54pm UTC](https://forum.djangoproject.com/t/html-and-json-fields-formatting-in-admins-modelform/27690/4 "2026-06-06T18:54:04Z")

</div>

There’s a read\_only ticket in the django bug tracker:

> **[\#30577 (Custom rendering for readonly fields in admin)
          – Django](https://code.djangoproject.com/ticket/30577)**

I think we need a generic solution to allow developers to write a readonly version of each widget cleanly without hacks.
