• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

derek-schaefer/django-json-field: Generic JSON model and form fields.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

derek-schaefer/django-json-field

开源软件地址:

https://github.com/derek-schaefer/django-json-field

开源编程语言:

Python 100.0%

开源软件介绍:

Django JSON Field

NOTE: This project is seeking new active maintainers.

django-json-field contains a flexible JSONField and associated form field. The model field is not only capable of serializing common JSON data types (int, float, decimal, string, time, date, datetime, etc.) but also lazily deserializing them so they can be accessed and modified as normal Python objects within Django.

A form field is also provided. It will accept serialized representations:

{"date": "2012-04-23T19:16:54.133", "num": "1.2399"}

And also provides safe access to the datetime module for explicit use:

{"date": datetime.datetime(2012, 4, 23, 19, 16, 54, 133000)}

While the JSON string will not be deserialized until it is accessed it can still be a performance concern, so you may find it valuable to disable the custom deserializer (JSONField(decoder=None)).

django-json-field is also compatible with South and Python 3.

Installation

Install from PyPI:

pip install django-json-field

If installing manually, first install the dependencies:

pip install python-dateutil six

Install from GitHub:

git clone git://github.com/derek-schaefer/django-json-field.git

pip install -e git+git://github.com/derek-schaefer/django-json-field.git#egg=json_field

Configuration

Add json_field to your PYTHONPATH and INSTALLED_APPS setting:

INSTALLED_APPS = (
    ...
    'json_field',
    ...
)

That's all!

Usage

Add a JSONField to your model like any other field.

from json_field import JSONField
from django.db import models

class MyModel(models.Model):

    json = JSONField()

JSONField also has a few additional optional parameters.

  • default: Falls back on "null" if not provided and null=False, otherwise None
  • db_type: Allows you to specify the column type (default: text)
  • lazy: Defer deserialization until the field is directly accessed (default: True)
  • encoder: Custom JSON encoder (default: DjangoJSONEncoder)
  • decoder: Custom JSON decoder (default: json_field.fields.JSONDecoder)
  • encoder_kwargs: Specify all arguments to the encoder (overrides encoder)
  • decoder_kwargs: Specify all arguments to the decoder (overrides decoder)
  • evaluate_formfield: Evaluate (risky) and enable use of the datetime module in the form field (default: False)

License

django-json-field is licensed under the New BSD license.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap