GithubHelp home page GithubHelp logo

dldevinc / django-spectrum Goto Github PK

View Code? Open in Web Editor NEW
3.0 4.0 1.0 253 KB

Provides an colorpicker field for use in Django models

License: BSD 3-Clause "New" or "Revised" License

Python 92.14% CSS 1.45% JavaScript 5.67% HTML 0.75%
django color colorpicker

django-spectrum's Introduction

django-spectrum

Provides a colorpicker field for Django

image

PyPI Build Status

Compatibility

  • python >= 3.6
  • django >= 1.11

Quickstart

Install django-spectrum:

pip install django-spectrum

Add 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")

Color class

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)

django-spectrum's People

Contributors

pix666 avatar erosendo avatar

Stargazers

 avatar Nikolaus Schlemm avatar

Watchers

James Cloos avatar  avatar  avatar  avatar

Forkers

erosendo

django-spectrum's Issues

Default for ColorField must be instance of Color

If default value for ColorField is not an instance of Color, then get_prep_value errors when making migrations or initializing model as encode_color errors with str instance does not have attribute 'opaque'

Passing color to html, css

Hello everyone,
I am kinda new to this, and I am creating a small website and I need this.
I wonder if I set color in Django admin, how can I transfer that color to HTML (background color in div, etc)

Thanks

Throws "django is not defined" Javascript error in browser console

Python 3.6
Django 2.1.8
wagtail 2.4

The widget does not initialize in admin and throws a "django is not defined" error in browser console. I traced it back to the last line of venv/lib/python3.6/site-packages/spectrum/static/spectrum/js/widget.js

which is

})(django.jQuery || jQuery);

Apparently the django global object is not available in this context so replacing it with

})(jQuery);

makes the error go away.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.