Package: django-jsonfield-backport
Backport of the cross-DBJSONFieldmodel and form fields from Django 3.1.fromdjango.dbimportmodelsfromdjango_jsonfield_backport.modelsimportJSONFieldclassContactInfo(models.Model):data=JSONField()ContactInfo.objects.create(data={'name':'John','cities':['London','Cambridge'],'pets':{'dogs':['Rufus','Meg']},})ContactInfo.objects.filter(data__name='John',data__pets__has_key='dogs',data__cities__contains='London',).delete()FeaturesMost features of the JSONField model and form fields from Django 3.1 are
supported.MariaDB, MySQL, Oracle, PostgreSQL, and SQLite support.JSONField lookups and transforms support.Custom encoder and decoder support.Due to limited access to Django’s APIs, some features are not supported.Introspection is not supported.On MariaDB and Oracle,Casting to JSONField must be done using the
includedJSONCastclass.This package is fully compatible with the JSONField from Django 3.1. That
means you just need to change your imports and edit your migrations when you
finally upgrade to Django 3.1. If you leave them as they are, this package
will use the built-in JSONField and system warnings will be raised.RequirementsThis package supports and is tested against the latest patch versions of:Python:3.5 (Django 2.2 only), 3.6, 3.7, 3.8, 3.9Django:2.2, 3.0, 3.1MariaDB:10.2, 10.3, 10.4, 10.5MySQL:5.7, 8.0Oracle:12.2+ (only tested against 12.2.0.1 SE)PostgreSQL:9.5, 10, 11, 12SQLite:3.9.0+ with theJSON1extensionAll database backends are tested with the latest versions of their drivers.
SQLite is also tested on GitHub Actions’ latest macOS and Windows virtual
environments.InstallationUsepipor your preferred dependency management tool to install the package.$pipinstalldjango-jsonfield-backportAdd"django_jsonfield_backport"toINSTALLED_APPSin your settings.INSTALLED_APPS=[..."django_jsonfield_backport",]UsageTo use the model and form fields, importJSONFieldfromdjango_jsonfield_backport.modelsanddjango_jsonfield_backport.forms,
respectively.Model field example:fromdjango.dbimportmodelsfromdjango_jsonfield_backport.modelsimportJSONFieldclassContactInfo(models.Model):data=JSONField()Form field example:fromdjangoimportformsfromdjango_jsonfield_backport.formsimportJSONFieldclassContactForm(forms.Form):data=JSONField()JSONCast,KeyTransform, andKeyTextTransformclasses are also
available fromdjango_jsonfield_backport.models.DocumentationSince this package is a backport, the official Django 3.1 docs formodels.JSONFieldandforms.JSONFieldare mostly compatible with this
package.RationaleAs of the creation of this package, JSONField implementations exist in multiple
packages on PyPI:Django:
Before Django 3.1, PostgreSQL-only JSONField exists in thecontrib.postgresmodule.jsonfield:
1.1k stars, cross-DB support with no extended querying capabilities.django-annoying:
787 stars, has aTextField-based JSONField with no extended querying
capabilities.Django-MySQL:
364 stars, has a MariaDB/MySQL-only JSONField with extended querying
capabilities (not entirely the same as incontrib.postgres).django-jsonfallback:
26 stars, uses JSONField fromcontrib.postgresand Django-MySQL before
falling back toTextField-based JSONField.django-json-field:
116 stars,TextField-based JSONField with custom encoder and decoder
support with no extended querying capabilities (unmaintained).django-jsonfield:
21 stars, cross-DB support with no extended querying capabilities.django-jsonfield-compat:
8 stars, compatibility layer forcontrib.postgresJSONField and
django-jsonfield.oracle-json-field:
2 stars, Oracle-only JSONField with extended querying capabilities
(not entirely the same as incontrib.postgres).Along with other unmaintained packages such asdj-jsonfield,vlk-django-jsonfield,linaro-django-jsonfield,jsonfield2,django-jsonfield2,django-softmachine,django-simple-jsonfield,easy_jsonfield, anddjango-jsonbfield.Why create another one?Up until the new JSONField in Django 3.1, there had been no implementation of
JSONField that supports all the database backends supported by Django with more
or lessthe same functionalitiesas thecontrib.postgresJSONField
provides.Django’s release processdoes not backport new features to previous feature
releases. However, the current LTS release is 2.2 which is still supported until
April 2022. The next LTS release is Django 3.2 in April 2021 that happens to be
the end of extended support for Django 3.1.Some projects only use LTS releases of Django. There are also incompatibilities
between Django 3.0 and 3.1. Therefore, using Django 3.1 may not be an option for
some people at the moment.Since JSONField seems to be in popular demand and that it works well as a
standalone package, I decided to create a backport.Besides, I’m theco-author of the new JSONField. ¯\_(ツ)_/¯LicenseThis package is licensed under theBSD 3-Clause License.