• Stars
    star
    519
  • Rank 82,340 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created about 14 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐ŸŽจ color field for django models with a nice color-picker in the admin.

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. ๐ŸงŸโ€โ™‚๏ธ

More Repositories

1

FCUUID

๐Ÿ“ฑ ๐Ÿ†” iOS UUID / Universally Unique Identifiers library as alternative to UDID and identifierForVendor.
Objective-C
1,574
star
2

django-admin-interface

๐Ÿฆธ โšก django's default admin interface with superpowers - customizable themes, popup windows replaced by modals and many other features.
CSS
1,546
star
3

python-benedict

๐Ÿ“˜ dict subclass with keylist/keypath support, built-in I/O operations (base64, csv, ini, json, pickle, plist, query-string, toml, xls, xml, yaml), s3 support and many utilities.
Python
1,111
star
4

FCFileManager

๐Ÿ“ฑ ๐Ÿ“‚ iOS file manager on top of NSFileManager for simplifying files management.
Objective-C
899
star
5

django-treenode

๐ŸŒณ probably the best abstract model/admin for your tree based stuff.
Python
481
star
6

django-maintenance-mode

๐Ÿšง ๐Ÿ› ๏ธ shows a 503 error page when maintenance-mode is on.
Python
408
star
7

django-extra-settings

โš™๏ธ config and manage typed extra settings using just the django admin.
Python
359
star
8

FCCurrentLocationGeocoder

๐Ÿ“ฑ ๐Ÿ“ iOS geocoder for forward / reverse geocode user's current location using a block-based syntax.
Objective-C
262
star
9

python-fsutil

๐Ÿ’ป ๐Ÿ”ง high-level file-system operations for lazy devs.
Python
147
star
10

FCIPAddressGeocoder

๐Ÿ“ฑ ๐ŸŒ iOS geocoder for geocode device IP Address location using GeoIP service(s) and a block-based syntax.
Objective-C
114
star
11

django-freeze

๐ŸงŠ convert your dynamic django site to a static one with one line of code.
Python
89
star
12

python-codicefiscale

๐Ÿ‡ฎ๐Ÿ‡น ๐Ÿ’ณ italian fiscal codes encoding, decoding and validation - codifica, decodifica e validazione del Codice Fiscale italiano.
Python
62
star
13

django-redirects

โ†ช๏ธ โœ… redirects as they should be, with full control.
Python
55
star
14

python-fontbro

๐Ÿงข friendly font operations on top of fontTools.
Python
41
star
15

utils.js

๐Ÿ‘ท ๐Ÿ”ง zero dependencies vanilla JavaScript utils.
JavaScript
18
star
16

create-matrix-action

๐Ÿงช ๐Ÿ’ฅ GitHub action that creates a non-square matrix parsing a readable config.
Python
9
star
17

layers.css

๐Ÿ“‘ pure (s)css independent stacked layers, no js at all.
CSS
8
star
18

wall.css

๐Ÿงฑ pure (s)css block-grid implementation with extra features.
SCSS
8
star
19

FCMapsApp

๐Ÿ“ฑ ๐Ÿ—บ๏ธ iOS utility for launching external maps applications (Apple Maps, Google Maps, Waze, Yandex Maps), showing locations and getting directions.
Objective-C
7
star
20

FCUtils

๐Ÿ“ฑ ๐Ÿ”ง iOS utilities collection.
Objective-C
6
star
21

python-imageutil

๐ŸŽฉ ๐Ÿช„ high-level image operations, with a bit of magic. ๐Ÿฐ
Python
5
star
22

xhrm.js

JavaScript XMLHttpRequest manager built on top of jQuery $.ajax.
JavaScript
2
star
23

tabbo.js

๐Ÿซ โŒจ๏ธ enhanced keyboard tabbing usability on any website / webapp with one line of code.
JavaScript
1
star