Skip to content

JhonFrederick/django-attributesjsonfield

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published