Skip to main content

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

Project description

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(model.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.

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

class MyModel(model.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(model.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(model.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

# create python virtual environment
virtualenv testing_django_colorfield

# activate virtualenv
cd testing_django_colorfield && . bin/activate

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

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

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

Credits

Originally developed by Jared Forsyth


License

Released under MIT License.


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. 🧟‍♂️

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-colorfield-0.6.0.tar.gz (49.9 kB view details)

Uploaded Source

Built Distribution

django_colorfield-0.6.0-py3-none-any.whl (48.1 kB view details)

Uploaded Python 3

File details

Details for the file django-colorfield-0.6.0.tar.gz.

File metadata

  • Download URL: django-colorfield-0.6.0.tar.gz
  • Upload date:
  • Size: 49.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.10

File hashes

Hashes for django-colorfield-0.6.0.tar.gz
Algorithm Hash digest
SHA256 aee0ad2d1f7cac2da205a5a0b9d2e5f2303f378d79ad846448d4c18fd262adc9
MD5 ffcd93829e2a58b487b9f8a83420495e
BLAKE2b-256 492592fdcbb172bdca1f3d634bb64cfbd484be4b61e7aa0c9f65610f4eef4aa6

See more details on using hashes here.

File details

Details for the file django_colorfield-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: django_colorfield-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 48.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.10

File hashes

Hashes for django_colorfield-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af407a87d4a1958ecd334fef230ce3288d2c2b47d191270b003b911dbe276194
MD5 2bb04bd7ae6cb2861e72e3dc12899d8e
BLAKE2b-256 4e35d7b949e77420f076bca2bc3c4dd4f1bc8fa00cc94dbcc02f2b826a1b7911

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page