Giter Club home page Giter Club logo

django-jsonfield2's Introduction

Django-JSONField2

django-json-field2 is a flexible quering JSONField and associated form field

It is a compilation and adaptation of the following projects

Feature Description

South support Form field Form widget Model field Python3 support

django-jsonfield2 is also compatible with South, Django 1.8 and Python 3.

Installation

Install from PyPI:

pip install django-jsonfield2

Source:

git clone git://github.com/DarioGT/django-jsonfield2.git

Configuration

Add jsonfield2 to your PYTHONPATH and INSTALLED_APPS setting:

INSTALLED_APPS = (
    ...
    'jsonfield2',
    ...
)

Usage

from django.db import models
    from jsonfield2 import JSONField, JSONAwareManager

    class JsonModel(models.Model):
        code = models.CharField( blank=False, null=False, max_length=20 )
        status = models.CharField( blank=True, null=True, max_length=20 )

        info = JSONField(default={})

        objects = JSONAwareManager(json_fields = ['info'])

        def __str__(self):
            return self.code

Json Query

...
obj = Person.objects.create(name = "Bill")
obj.info = {
    'sex': 'male',
    'address': {
        'country', 'Canada',
    }
}
obj.save()
Person.objects.filter(info__address__country = 'Canada')
>>> [Person: "Bill"]

Usage

Now, it will validate the JSON on entry, and store it as a text in the database. When you instantiate/fetch the object, it will be turned back into a python list/dict/string.

jsonify templatetag

This allows you to convert a python data structure into JSON within a template:

{% load jsonify %}

<script>
var foo = {{ bar|jsonify }};
</script>

Tests

python runtest.py

Todo

Allow order_by when json criteria are used

License

django-jsonfield2 is licensed under the New BSD license.

django-jsonfield2's People

Contributors

dariogt avatar katobr avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

django-jsonfield2's Issues

SubfieldBase has been deprecated. Use Field.from_db_value

We need to update this module for future Django release to fix this warning:

RemovedInDjango110Warning: SubfieldBase has been deprecated. Use Field.from_db_value instead.
  class JSONField(six.with_metaclass(models.SubfieldBase, models.Field)):

I will send in a PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.