Skip to content

Latest commit

 

History

History
63 lines (53 loc) · 1.54 KB

README.md

File metadata and controls

63 lines (53 loc) · 1.54 KB

Django AttributesJsonField

Any color you like

Django package that extends the JsonField limiting possible keys of the Json.

Requirements

Python 3.7 or newer with Django >= 2.2 or newer.

Installation

  1. Install using pip.
pip intall git+https://github.com/JhonFrederick/django-attributesjsonfield.git 
  1. Add attributesjsonfield to settings.INSTALLED_APPS.
INSTALLED_APPS = (
    # ...
    "attributesjsonfield",
    # ...
)

Usage

Models

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

License

Released under MIT License.