Django package that extends the JsonField limiting possible keys of the Json.
Python 3.7 or newer with Django >= 2.2 or newer.
- Install using pip.
pip intall git+https://github.com/JhonFrederick/django-attributesjsonfield.git
- Add
attributesjsonfield
tosettings.INSTALLED_APPS
.
INSTALLED_APPS = (
# ...
"attributesjsonfield",
# ...
)
Just add AttributesJSONField to your models like this:
Simple attribute
from django.db import models
from attributesjsonfield.models.fields import AttributesJSONField
class MyModel(models.Model):
simple_attribute_field = AttributesJSONField(
"format",
"value",
],
)
Complex attribute
class MyModel(models.Model):
complex_attribute_field = AttributesJSONField(
attributes=[
{
"field": "format",
"required": False,
"choices": (("pdf", "PDF"), ("word", "word")),
"verbose_name": "format type",
}
],
)
For complex attributes, the following keys are accepted:
- "field": Attribute name
- "required": True or False, default is True
- "choices": Limits the input to the particular values specified
- "verbose_name": Human-readable name for the field
Released under MIT License.