Skip to content

Instantly share code, notes, and snippets.

@wwarne
wwarne / json_schemed_field.py
Last active September 23, 2021 18:55 — forked from Bahus/json_schemed_field.py
Django JSONField with Pydantic schema support
from functools import partial
import pydantic
import logging
from django.contrib.postgres.fields import JSONField
from typing import Type, Union, Tuple
from django.core.serializers.json import DjangoJSONEncoder
import base64
import hashlib
import hmac
import textwrap
# key and salt can be generated via echo $(xxd -g 2 -l 64 -p /dev/random | tr -d '\n')
IMGPROXY_KEY='5360fd1a41998f8c568127a3053f26960d69e735530d5e5df9dcb3e4c4dff8cb55b23cf459f94baf7dbda42400d36006b080881187d80f1bb9f52731df6b8b5b'
IMGPROXY_SALT='d9a8a7419ca0dd96214a02c29c5f88b835fbb4a9dd788359cc753f9ac18233b52c1bea5cf87257d2e0730c8c8aa88dbd347616cc3cd3dbeb3241356c9392d9cd'