在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:rpkilby/jsonfield开源软件地址:https://github.com/rpkilby/jsonfield开源编程语言:Python 100.0%开源软件介绍:jsonfieldjsonfield is a reusable model field that allows you to store validated JSON, automatically handling
serialization to and from the database. To use, add 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. Requirementsjsonfield aims to support all current versions of Django, however the explicity tested versions are:
Installationpip install jsonfield Usagefrom django.db import models
from jsonfield import JSONField
class MyModel(models.Model):
json = JSONField() QueryingAs stated above, Handling null valuesA model field's This in turn affects how null values may be queried. Both fields support exact matching: MyModel.objects.filter(json=None) However, if you want to use the class MyModel(models.Model):
json = JSONField(null=True)
MyModel.objects.filter(json__isnull=True) Note that as Advanced UsageBy 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 collections
class MyModel(models.Model):
json = JSONField(load_kwargs={'object_pairs_hook': collections.OrderedDict}) Other Fieldsjsonfield.JSONCharField Subclasses models.CharField instead of models.TextField. Running the testsThe test suite requires $ pip install tox Then, run the $ tox Or, to test just one job (for example Django 2.0 on Python 3.6): $ tox -e py36-django20 Release Process
$ 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/* ChangesTake a look at the changelog. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论