jsonfield下载 - Django模型字段用于存储临时JSON数据

1035 2020-03-10 Python MIT 官方网站



1.0.3.zip(1.0.3) 下载

2.0.0.zip(2.0.0) 下载

2.0.1.zip(2.0.1) 下载

1.0.2.zip(1.0.3) 下载

3.1.0.zip(3.1.0) 下载



jsonfield is a reusable model field that allows you to store validated JSON, automatically handling serialization to and from the database. To use, add jsonfield.JSONField to one of your models.

Note: django.contrib.postgres now supports PostgreSQL's jsonb type, which includes extended querying capabilities. If you're an end user of PostgreSQL and want full-featured JSON support, then it is recommended that you use the built-in JSONField. However, jsonfield is still useful when your app needs to be database-agnostic, or when the built-in JSONField's extended querying is not being leveraged. e.g., a configuration field.


jsonfield aims to support all current versions of Django, however the explicity tested versions are:

  • Python: 3.6, 3.7, 3.8

  • Django: 2.2, 3.0


pip install jsonfield


from django.db import modelsfrom jsonfield import JSONFieldclass MyModel(models.Model):
    json = JSONField()

Advanced Usage

By default python deserializes json into dict objects. This behavior differs from the standard json behavior  because python dicts do not have ordered keys. To overcome this limitation and keep the sort order of OrderedDict keys the deserialisation can be adjusted on model initialisation:

import collectionsclass MyModel(models.Model):
    json = JSONField(load_kwargs={'object_pairs_hook': collections.OrderedDict})

Other Fields


Subclasses models.CharField instead of models.TextField.

Running the tests

The test suite requires tox and tox-venv.

$ pip install tox tox-venv

To test against all supported versions of Django, install and run tox:

$ tox

Or, to test just one version (for example Django 2.0 on Python 3.6):

$ tox -e py36-django20

Release Process

  • Update changelog

  • Update package version in setup.py

  • Check supported versions in setup.py and readme

  • Create git tag for version

  • Upload release to PyPI test server

  • Upload release to official PyPI server

$ pip install -U pip setuptools wheel twine
$ rm -rf dist/ build/
$ python setup.py sdist bdist_wheel
$ twine upload -r test dist/*$ twine upload dist/*


Take a look at the changelog.