Add new package to help with editing JSON fields

This commit is contained in:
Ramon Wenger 2023-04-25 17:23:58 +02:00
parent 34546d35e2
commit 9dd9a02592
6 changed files with 43 additions and 4 deletions

View File

@ -101,6 +101,7 @@ THIRD_PARTY_APPS = [
"grapple", "grapple",
"graphene_django", "graphene_django",
"notifications", "notifications",
"django_jsonform",
] ]
LOCAL_APPS = [ LOCAL_APPS = [

View File

@ -26,6 +26,7 @@ django-ipware
django-csp django-csp
django-storages django-storages
django-notifications-hq django-notifications-hq
django-jsonform
psycopg2-binary psycopg2-binary
gunicorn gunicorn

View File

@ -62,6 +62,7 @@ django==3.2.13
# django-cors-headers # django-cors-headers
# django-csp # django-csp
# django-filter # django-filter
# django-jsonform
# django-model-utils # django-model-utils
# django-modelcluster # django-modelcluster
# django-notifications-hq # django-notifications-hq
@ -87,6 +88,8 @@ django-filter==21.1
# via wagtail # via wagtail
django-ipware==4.0.2 django-ipware==4.0.2
# via -r requirements.in # via -r requirements.in
django-jsonform==2.17.0
# via -r requirements.in
django-model-utils==4.2.0 django-model-utils==4.2.0
# via # via
# -r requirements.in # -r requirements.in

View File

@ -8,9 +8,6 @@ from vbv_lernwelt.learnpath.models import Circle
@admin.register(CourseSession) @admin.register(CourseSession)
class CourseSessionAdmin(admin.ModelAdmin): class CourseSessionAdmin(admin.ModelAdmin):
formfield_overrides = {
JSONField: {"widget": PrettyJSONWidget(attrs={"rows": 16, "cols": 80})},
}
date_hierarchy = "created_at" date_hierarchy = "created_at"
list_display = [ list_display = [
"title", "title",

View File

@ -0,0 +1,19 @@
# Generated by Django 3.2.13 on 2023-04-25 12:28
from django.db import migrations
import django_jsonform.models.fields
class Migration(migrations.Migration):
dependencies = [
('course', '0004_coursesession_assignment_details_list'),
]
operations = [
migrations.AlterField(
model_name='coursesession',
name='attendance_days',
field=django_jsonform.models.fields.JSONField(),
),
]

View File

@ -3,6 +3,7 @@ from django.db.models import UniqueConstraint
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from wagtail.models import Page from wagtail.models import Page
from django_jsonform.models.fields import JSONField
from vbv_lernwelt.core.model_utils import find_available_slug from vbv_lernwelt.core.model_utils import find_available_slug
from vbv_lernwelt.core.models import User from vbv_lernwelt.core.models import User
@ -178,6 +179,23 @@ class CourseSession(models.Model):
Das anhängen kann via CourseSessionUser oder "Schulklasse (TODO)" geschehen Das anhängen kann via CourseSessionUser oder "Schulklasse (TODO)" geschehen
""" """
ATTENDANCE_DAYS_SCHEMA = {
"type": "array",
"items": {
"type": "object",
"properties": {
"learningContentId": {
"type": "number",
"title": "ID des Lerninhalts",
"required": True,
},
"date": {"type": "string"},
"location": {"type": "string"},
"trainer": {"type": "string"},
},
},
}
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True) updated_at = models.DateTimeField(auto_now=True)
@ -187,7 +205,7 @@ class CourseSession(models.Model):
start_date = models.DateField(null=True, blank=True) start_date = models.DateField(null=True, blank=True)
end_date = models.DateField(null=True, blank=True) end_date = models.DateField(null=True, blank=True)
attendance_days = models.JSONField(default=list, blank=True) attendance_days = JSONField(schema=ATTENDANCE_DAYS_SCHEMA, blank=True, default=list)
assignment_details_list = models.JSONField(default=list, blank=True) assignment_details_list = models.JSONField(default=list, blank=True)
additional_json_data = models.JSONField(default=dict, blank=True) additional_json_data = models.JSONField(default=dict, blank=True)