Coder Social home page Coder Social logo

fabiocaccamo / django-colorfield Goto Github PK

View Code? Open in Web Editor NEW
576.0 7.0 95.0 370 KB

:art: color field for django models with a nice color-picker in the admin.

License: MIT License

Python 96.90% HTML 1.74% JavaScript 1.36%
django colorfield colorpicker color field picker model admin python models

django-colorfield's Introduction

django-colorfield

simple color field for your models with a nice color-picker in the admin-interface.

django-colorfield-hex django-colorfield-hexa


Installation

  • Run pip install django-colorfield
  • Add colorfield to settings.INSTALLED_APPS
  • Run python manage.py collectstatic
  • Restart your application server

Usage

Settings

This package doesn't need any setting.

Models

Just add color field(s) to your models like this:

from colorfield.fields import ColorField
from django.db import models

class MyModel(models.Model):
    color = ColorField(default='#FF0000')

Field Options

These are the supported custom options: format, image_field, samples

format

The following formats are supported: hex (default), hexa, rgb, rgba.

from colorfield.fields import ColorField
from django.db import models

class MyModel(models.Model):
    color = ColorField(format="hexa")

image_field

It is possible to auto-populate the field value getting the color from an image using the image_field option.

The color will be calculated from the top-left pixel color of the image each time the model instance is saved.

from colorfield.fields import ColorField
from django.db import models

class MyModel(models.Model):
    image = models.ImageField(upload_to="images")
    color = ColorField(image_field="image")

samples

It is possible to provide a palette of colors to choose from to the widget using the samples option.

This option is not restrictive (on the contrary of choices option), it is also possible to choose another color from the spectrum.

django-colorfield-samples

from colorfield.fields import ColorField
from django.db import models

class MyModel(models.Model):

    COLOR_PALETTE = [
        ("#FFFFFF", "white", ),
        ("#000000", "black", ),
    ]

    # not restrictive, allows the selection of another color from the spectrum.
    color = ColorField(samples=COLOR_PALETTE)

    # restrictive, it is mandatory to choose a color from the palette
    color = ColorField(choices=COLOR_PALETTE)

Admin

The admin will kindly provide a simple color picker for all color fields. :)


Testing

# clone repository
git clone https://github.com/fabiocaccamo/django-colorfield.git && cd django-colorfield

# create virtualenv and activate it
python -m venv venv && . venv/bin/activate

# upgrade pip
python -m pip install --upgrade pip

# install requirements
pip install -r requirements.txt -r requirements-test.txt

# install pre-commit to run formatters and linters
pre-commit install --install-hooks

# run tests
tox
# or
python runtests.py
# or
python -m django test --settings "tests.settings"

Credits

Originally developed by Jared Forsyth


License

Released under MIT License.


Supporting

See also

  • django-admin-interface - the default admin interface made customizable by the admin itself. popup windows replaced by modals. ๐Ÿง™ โšก

  • django-extra-settings - config and manage typed extra settings using just the django admin. โš™๏ธ

  • django-maintenance-mode - shows a 503 error page when maintenance-mode is on. ๐Ÿšง ๐Ÿ› ๏ธ

  • django-redirects - redirects with full control. โ†ช๏ธ

  • django-treenode - probably the best abstract model / admin for your tree based stuff. ๐ŸŒณ

  • python-benedict - dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. ๐Ÿ“˜

  • python-codicefiscale - encode/decode Italian fiscal codes - codifica/decodifica del Codice Fiscale. ๐Ÿ‡ฎ๐Ÿ‡น ๐Ÿ’ณ

  • python-fontbro - friendly font operations. ๐Ÿงข

  • python-fsutil - file-system utilities for lazy devs. ๐ŸงŸโ€โ™‚๏ธ

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.