django-colorfield
simple color field for your models with a nice color-picker in the admin-interface.
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.
from colorfield.fields import ColorField
from django.db import models
class MyModel(models.Model):
COLOR_PALETTE = [
("#FFFFFF", "white", ),
("#000000", "black", ),
]
color = ColorField(samples=COLOR_PALETTE)
color = ColorField(choices=COLOR_PALETTE)
Admin
The admin will kindly provide a simple color picker for all color fields. :)
Testing
git clone https://github.com/fabiocaccamo/django-colorfield.git && cd django-colorfield
python -m venv venv && . venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt -r requirements-test.txt
pre-commit install --install-hooks
tox
python runtests.py
python -m django test --settings "tests.settings"
Credits
Originally developed by Jared Forsyth
License
Released under MIT License.
Supporting
- :star: Star this project on GitHub
- :octocat: Follow me on GitHub
- :blue_heart: Follow me on Twitter
- :moneybag: Sponsor me on Github
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. 🧟♂️