{"id":17136943,"url":"https://github.com/un-def/django-janyson","last_synced_at":"2025-04-13T09:22:25.113Z","repository":{"id":57420515,"uuid":"57244143","full_name":"un-def/django-janyson","owner":"un-def","description":"Virtual model fields that are transparently mapped to Postgres jsonb","archived":false,"fork":false,"pushed_at":"2016-06-02T15:44:00.000Z","size":61,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T00:54:57.706Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/un-def.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-27T20:05:47.000Z","updated_at":"2017-09-29T09:07:22.000Z","dependencies_parsed_at":"2022-09-16T09:11:07.046Z","dependency_job_id":null,"html_url":"https://github.com/un-def/django-janyson","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/un-def%2Fdjango-janyson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/un-def%2Fdjango-janyson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/un-def%2Fdjango-janyson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/un-def%2Fdjango-janyson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/un-def","download_url":"https://codeload.github.com/un-def/django-janyson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248689382,"owners_count":21145923,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T20:05:48.443Z","updated_at":"2025-04-13T09:22:25.089Z","avatar_url":"https://github.com/un-def.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Django JanySON\n==============\n\n[![Build Status](https://travis-ci.org/un-def/django-janyson.svg?branch=master)](https://travis-ci.org/un-def/django-janyson)\n[![Coverage Status](https://coveralls.io/repos/github/un-def/django-janyson/badge.svg?branch=master)](https://coveralls.io/github/un-def/django-janyson?branch=master)\n[![PyPI version](https://badge.fury.io/py/django-janyson.svg)](https://pypi.python.org/pypi/django-janyson/)\n[![PyPI license](https://img.shields.io/pypi/l/django-janyson.svg?maxAge=3600)](https://raw.githubusercontent.com/un-def/django-janyson/master/LICENSE)\n\nStore additional model fields as JSON object in PostgreSQL's `jsonb` field and work with them as regular model fields. Need new boolean/text/foreign key/many-to-many/etc. field? Just add the decorator with the field description to your model. It's all! No more annoying migrations.\n\n\n### Installation\n\n* Install the package using `pip install django-janyson`.\n* Add `janyson` to `INSTALLED_APPS` setting (optional).\n\n\n### Requirements\n\n* Python 2.7+ or 3.4+\n* Django 1.9+ with psycopg2\n* [six](https://pypi.python.org/pypi/six)\n\n\n### Example\n\n```python\nfrom django.db import models\n\nfrom janyson.decorators import add_fields\nfrom janyson.fields import JanySONField\n\n\nclass Tag(models.Model):\n\n    name = models.CharField(max_length=16)\n\n    def __str__(self):\n        return \"[Tag: {}]\".format(self.name)\n\n\nextra_fields = {\n    'desc': {'type': 'str'},\n    'qty': {'type': 'num', 'default': 0, 'use_default': True},\n    'avail': {'type': 'nullbool', 'use_default': True},\n    'main_tag': {'type': 'fk', 'model': Tag},\n    'tags': {'type': 'm2m', 'model': 'demo_app.Tag'},\n}\n\ncommon_options = {\n    'use_default': False,\n    'dir_hide': True,\n}\n\n@add_fields(extra_fields, field_options=common_options, janyson_field='extra')\nclass Item(models.Model):\n\n    name = models.CharField(max_length=64)\n    extra = JanySONField(verbose_name='janyson field', default=dict,\n                         blank=True, null=True)\n\n    def __str__(self):\n        return \"[Item: {}]\".format(self.name)\n```\n\n```python\n\u003e\u003e\u003e from demo_app.models import Tag, Item\n\n\u003e\u003e\u003e Tag.objects.create(name='tag1')\n\u003e\u003e\u003e Tag.objects.create(name='tag2')\n\u003e\u003e\u003e item = Item(name='test')\n\n\u003e\u003e\u003e item\n\u003cItem: [Item: test]\u003e\n\u003e\u003e\u003e item.desc\nAttributeError: 'Item' object has no attribute 'desc'\n\u003e\u003e\u003e item.qty\n0\n\u003e\u003e\u003e print(item.avail)\nNone\n\u003e\u003e\u003e item.tags\nAttributeError: 'Item' object has no attribute 'tags'\n\n\u003e\u003e\u003e tags = Tag.objects.all()\n\u003e\u003e\u003e item.desc = 'description'\n\u003e\u003e\u003e item.qty = 100\n\u003e\u003e\u003e item.avail = True\n\u003e\u003e\u003e item.tags = tags\n\u003e\u003e\u003e item.save()\n\n\u003e\u003e\u003e del item\n\u003e\u003e\u003e item = Item.objects.get(name='test')\n\u003e\u003e\u003e item.desc\n'description'\n\u003e\u003e\u003e item.qty\n100\n\u003e\u003e\u003e item.avail\nTrue\n\u003e\u003e\u003e item.tags\n[\u003cTag: [Tag: tag1]\u003e, \u003cTag: [Tag: tag1]\u003e, \u003cTag: [Tag: tag2]\u003e]\n```\n\n### Tests\n\n`$ python runtests.py [-d TESTDBNAME] [-h HOSTNAME] [-p PORT] [-U USERNAME] [-P PASSWORD] [-w]`\n\nRun `python runtests.py --help` for additional info.\n\nTest with multiple Python versions and measure code coverage (using [tox](https://pypi.python.org/pypi/tox) and [coverage.py](https://pypi.python.org/pypi/coverage)):\n\n```\n$ pip install -r requirements_dev.txt\n$ ./runtests.sh [TOX_OPTIONS] [-- RUNTESTS_OPTIONS]\n```\n\nExample:\n\n`$ ./runtests.sh -e py27,py35 -- -h 127.0.0.1 -p 5432 -U testuser -w`\n\n\n### Documentation\n\nComing soon.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fun-def%2Fdjango-janyson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fun-def%2Fdjango-janyson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fun-def%2Fdjango-janyson/lists"}