Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
simple color field for your models with a nice color-picker in the admin-interface.
pip install django-colorfield
colorfield
to settings.INSTALLED_APPS
python manage.py collectstatic
This package doesn't need any setting.
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')
These are the supported custom options: format
, image_field
, samples
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")
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")
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", ),
]
# 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)
The colorfield.fields.ColorField
can be used in Django model forms (django.forms.ModelForm
) to provide a color picker widget.
When used in a model form, the field automatically validates the color format based on the specified format
(e.g., hex
, rgb
, rgba
).
from django import forms
class MyModelForm(forms.ModelForm):
class Meta:
model = MyModel
fields = ["color"]
The colorfield.forms.ColorField
can be used in plain Django forms (django.forms.Form
) to provide a color-picker widget.
This is useful when you need a color input outside of a model context.
from django import forms
from colorfield.forms import ColorField
class MyForm(forms.Form):
color = ColorField(initial="#FF0000", format="hex")
The admin will kindly provide a simple color picker for all color fields. :)
# 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"
Originally developed by Jared Forsyth
Released under MIT License.
django-admin-interface
- the default admin interface made customizable by the admin itself. popup windows replaced by modals. 🧙 ⚡
django-cache-cleaner
- clear the entire cache or individual caches easily using the admin panel or management command. 🧹✨
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. 🧟♂️
FAQs
color field for django models with a nice color-picker in the admin.
We found that django-colorfield demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.