From f379920d66c55fd557059c2b28b3c88d6bbf7895 Mon Sep 17 00:00:00 2001 From: Antoine Mineau Date: Wed, 18 Oct 2023 11:17:22 +0200 Subject: [PATCH] add json viewer in admin --- platform_back/settings/admin/common.py | 1 + poetry.lock | 27 +++++++++++++++++++++++++- pyproject.toml | 1 + user/admin.py | 5 +++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/platform_back/settings/admin/common.py b/platform_back/settings/admin/common.py index bd1fd8e..7160f50 100644 --- a/platform_back/settings/admin/common.py +++ b/platform_back/settings/admin/common.py @@ -28,6 +28,7 @@ "django.contrib.admin", "django.contrib.messages", "django.contrib.admindocs", + "django_json_widget", ] MIDDLEWARE += [ diff --git a/poetry.lock b/poetry.lock index e2b28fe..effb3fa 100644 --- a/poetry.lock +++ b/poetry.lock @@ -586,6 +586,20 @@ django = ">=2.2" docs = ["sphinx"] test = ["celery", "pytest", "pytest-cov", "pytest-django", "redis"] +[[package]] +name = "django-json-widget" +version = "1.1.1" +description = "Django json widget is an alternative widget that makes it easy to edit the jsonfield field of django." +category = "main" +optional = false +python-versions = "*" +files = [ + {file = "django-json-widget-1.1.1.tar.gz", hash = "sha256:ec948a4c379687f9c854748ba540fdbeb1b1730846ca953f186818521de7e696"}, +] + +[package.dependencies] +future = "*" + [[package]] name = "django-postgres-extra" version = "2.0.8" @@ -763,6 +777,17 @@ files = [ [package.dependencies] msgpack = ">1.0" +[[package]] +name = "future" +version = "0.18.3" +description = "Clean single-source support for Python 3 and 2" +category = "main" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ + {file = "future-0.18.3.tar.gz", hash = "sha256:34a17436ed1e96697a86f9de3d15a3b0be01d8bc8de9c1dffd59fb8234ed5307"}, +] + [[package]] name = "gunicorn" version = "20.1.0" @@ -1604,4 +1629,4 @@ brotli = ["Brotli"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "96e16e90bc9693659929cbc47ca348b79ee1c32703b5a4a26e35ed70cc3a34c3" +content-hash = "02eaf79e96bd331e6f58336a1084a8ce18558817305533322ceab32d7570b482" diff --git a/pyproject.toml b/pyproject.toml index 3e3313d..30a96f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ python-dotenv = "^0.17.0" requests = "^2.28.2" whitenoise = "^5.3.0" django-cron = "^0.6.0" +django-json-widget = "^1.1.1" [tool.poetry.group.deploy] optional = true diff --git a/user/admin.py b/user/admin.py index 90bcbd7..472adf8 100644 --- a/user/admin.py +++ b/user/admin.py @@ -4,6 +4,8 @@ # file that was distributed with this source code. from django.contrib import admin from django.contrib.auth.admin import UserAdmin +from django.db import models +from django_json_widget.widgets import JSONEditorWidget from user.models import GuidedTour from user.models import Notification @@ -30,6 +32,9 @@ class GuidedTourAdmin(admin.ModelAdmin): @admin.register(Notification) class NotificationAdmin(admin.ModelAdmin): + formfield_overrides = { + models.JSONField: {"widget": JSONEditorWidget}, + } list_display = ("user", "cloud_id", "event", "event_type", "consumed", "created_at") list_filter = ( "event_type",