Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DESCRIPTION.rst 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. django-jsonfield
  2. ----------------
  3. django-jsonfield is a reusable Django field that allows you to store validated JSON in your model.
  4. It silently takes care of serialization. To use, simply add the field to one of your models.
  5. Python 3 & Django 1.8 through 1.11 supported!
  6. **Use PostgreSQL?** 1.0.0 introduced a breaking change to the underlying data type, so if you were using < 1.0.0 please read https://github.com/dmkoch/django-jsonfield/issues/57 before upgrading. Also, consider switching to Django's native JSONField that was added in Django 1.9.
  7. **Note:** There are a couple of third-party add-on JSONFields for Django. This project is django-jsonfield here on GitHub but is named `jsonfield on PyPI`_. There is another `django-jsonfield on Bitbucket`_, but that one is `django-jsonfield on PyPI`_. I realize this naming conflict is confusing and I am open to merging the two projects.
  8. .. _jsonfield on PyPI: https://pypi.python.org/pypi/jsonfield
  9. .. _django-jsonfield on Bitbucket: https://bitbucket.org/schinckel/django-jsonfield
  10. .. _django-jsonfield on PyPI: https://pypi.python.org/pypi/django-jsonfield
  11. **Note:** Django 1.9 added native PostgreSQL JSON support in `django.contrib.postgres.fields.JSONField`_. This module is still useful if you need to support JSON in databases other than PostgreSQL or are creating a third-party module that needs to be database-agnostic. But if you're an end user using PostgreSQL and want full-featured JSON support, I recommend using the built-in JSONField from Django instead of this module.
  12. .. _django.contrib.postgres.fields.JSONField: https://docs.djangoproject.com/en/dev/ref/contrib/postgres/fields/#jsonfield
  13. **Note:** Semver is followed after the 1.0 release.
  14. Installation
  15. ------------
  16. .. code-block:: python
  17. pip install jsonfield
  18. Usage
  19. -----
  20. .. code-block:: python
  21. from django.db import models
  22. from jsonfield import JSONField
  23. class MyModel(models.Model):
  24. json = JSONField()
  25. Advanced Usage
  26. --------------
  27. By default python deserializes json into dict objects. This behavior differs from the standard json behavior because python dicts do not have ordered keys.
  28. To overcome this limitation and keep the sort order of OrderedDict keys the deserialisation can be adjusted on model initialisation:
  29. .. code-block:: python
  30. import collections
  31. class MyModel(models.Model):
  32. json = JSONField(load_kwargs={'object_pairs_hook': collections.OrderedDict})
  33. Other Fields
  34. ------------
  35. **jsonfield.JSONCharField**
  36. If you need to use your JSON field in an index or other constraint, you can use **JSONCharField** which subclasses **CharField** instead of **TextField**. You'll also need to specify a **max_length** parameter if you use this field.
  37. Compatibility
  38. --------------
  39. django-jsonfield aims to support the same versions of Django currently maintained by the main Django project. See `Django supported versions`_, currently:
  40. * Django 1.8 (LTS) with Python 2.7, 3.3, 3.4, or 3.5
  41. * Django 1.9 with Python 2.7, 3.4, or 3.5
  42. * Django 1.10 with Python 2.7, 3.4, or 3.5
  43. * Django 1.11 (LTS) with Python 2.7, 3.4, 3.5 or 3.6
  44. .. _Django supported versions: https://www.djangoproject.com/download/#supported-versions
  45. Testing django-jsonfield Locally
  46. --------------------------------
  47. To test against all supported versions of Django:
  48. .. code-block:: shell
  49. $ docker-compose build && docker-compose up
  50. Or just one version (for example Django 1.10 on Python 3.5):
  51. .. code-block:: shell
  52. $ docker-compose build && docker-compose run tox tox -e py35-1.10
  53. Travis CI
  54. ---------
  55. .. image:: https://travis-ci.org/dmkoch/django-jsonfield.svg?branch=master
  56. :target: https://travis-ci.org/dmkoch/django-jsonfield
  57. Contact
  58. -------
  59. Web: http://bradjasper.com
  60. Twitter: `@bradjasper`_
  61. Email: `contact@bradjasper.com`_
  62. .. _contact@bradjasper.com: mailto:contact@bradjasper.com
  63. .. _@bradjasper: https://twitter.com/bradjasper
  64. Changes
  65. -------
  66. Take a look at the `changelog`_.
  67. .. _changelog: https://github.com/dmkoch/django-jsonfield/blob/master/CHANGES.rst