Last active
November 28, 2024 23:53
-
-
Save douglasmiranda/17432b5261aa0a5980069bd9bf2de6c5 to your computer and use it in GitHub Desktop.
Django Admin - Pretty Print (formatted / idented / no color) JSON (read-only)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IMPORTANT: Just keep in mind this is not ideal for untrusted JSON content. | |
import json | |
from django.contrib import admin | |
from .models import Publication | |
@admin.register(Publication) | |
class PublicationAdmin(admin.ModelAdmin): | |
readonly_fields = ( | |
"pretty_meta_info", | |
) | |
@admin.display(description="Meta Info") | |
def pretty_meta_info(self, publication): | |
pretty_json = json.dumps(publication.meta_info, indent=4, sort_keys=True) | |
return mark_safe(f"<pre>{pretty_json}</pre>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment