Provides a colorpicker field for Django
python>= 3.6django>= 1.11
Install django-spectrum:
pip install django-spectrumAdd it to your INSTALLED_APPS list:
INSTALLED_APPS = (
...
"spectrum",
)Then add it to your models:
from django.db import models
from spectrum.fields import ColorField
class MyModel(models.Model):
color = ColorField(_("color"), default="#FFFF00")The module defines a Color class which is used to represent the ColorField
attribute on the model. The Color class can also be used standalone without
any Django model.
Some examples of funcionality provided by the Color class:
from spectrum.color import Color
c = Color("#FFDA0080")
>>> print(c.red)
255
>>> print(c.alpha)
128
>>> print(c.hex)
#FFDA00
>>> print(c.hexa)
#FFDA0080
>>> print(c.rgb)
rgb(255, 218, 0)
>>> print(c.rgba)
rgba(255, 218, 0, 0.5)
>>> print(c.opacity)
0.5
>>> print(c.as_tuple())
(255, 218, 0, 128)