Name | django-colorfield JSON |
Version |
0.12.0
JSON |
| download |
home_page | None |
Summary | color field for django models with a nice color-picker in the admin. |
upload_time | 2025-01-27 18:30:16 |
maintainer | None |
docs_url | None |
author | None |
requires_python | None |
license | MIT License
Copyright (c) 2013-present Jared Forsyth / Fabio Caccamo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|
keywords |
django
colorfield
colorpicker
color
field
picker
chooser
admin
python
|
VCS |
 |
bugtrack_url |
|
requirements |
django
Pillow
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[](https://www.python.org/)
[](https://www.djangoproject.com/)
[](https://pypi.org/project/django-colorfield/)
[](https://pepy.tech/project/django-colorfield)
[](https://github.com/fabiocaccamo/django-colorfield/stargazers)
[](https://github.com/fabiocaccamo/django-colorfield/blob/main/LICENSE.txt)
[](https://results.pre-commit.ci/latest/github/fabiocaccamo/django-colorfield/main)
[](https://github.com/fabiocaccamo/django-colorfield)
[](https://codecov.io/gh/fabiocaccamo/django-colorfield)
[](https://www.codacy.com/app/fabiocaccamo/django-colorfield)
[](https://codeclimate.com/github/fabiocaccamo/django-colorfield/)
[](https://github.com/psf/black)
[](https://github.com/astral-sh/ruff)
# 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:
```python
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`](#format), [`image_field`](#image_field), [`samples`](#samples)
#### format
The following formats are supported: `hex` *(default)*, `hexa`, `rgb`, `rgba`.
```python
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.
```python
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.

```python
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)
```
### Forms
#### Model forms
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`).
```python
from django import forms
class MyModelForm(forms.ModelForm):
class Meta:
model = MyModel
fields = ["color"]
```
#### Plain forms
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.
```python
from django import forms
from colorfield.forms import ColorField
class MyForm(forms.Form):
color = ColorField(initial="#FF0000", format="hex")
```
### Admin
The admin will kindly provide a simple [color picker](http://jscolor.com/) for all color fields. :)
---
## Testing
```bash
# 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](https://github.com/jaredly)
---
## License
Released under [MIT License](LICENSE.txt).
---
## Supporting
- :star: Star this project on [GitHub](https://github.com/fabiocaccamo/django-colorfield)
- :octocat: Follow me on [GitHub](https://github.com/fabiocaccamo)
- :blue_heart: Follow me on [Twitter](https://twitter.com/fabiocaccamo)
- :moneybag: Sponsor me on [Github](https://github.com/sponsors/fabiocaccamo)
## See also
- [`django-admin-interface`](https://github.com/fabiocaccamo/django-admin-interface) - the default admin interface made customizable by the admin itself. popup windows replaced by modals. ๐ง โก
- [`django-cache-cleaner`](https://github.com/fabiocaccamo/django-cache-cleaner) - clear the entire cache or individual caches easily using the admin panel or management command. ๐งนโจ
- [`django-extra-settings`](https://github.com/fabiocaccamo/django-extra-settings) - config and manage typed extra settings using just the django admin. โ๏ธ
- [`django-maintenance-mode`](https://github.com/fabiocaccamo/django-maintenance-mode) - shows a 503 error page when maintenance-mode is on. ๐ง ๐ ๏ธ
- [`django-redirects`](https://github.com/fabiocaccamo/django-redirects) - redirects with full control. โช๏ธ
- [`django-treenode`](https://github.com/fabiocaccamo/django-treenode) - probably the best abstract model / admin for your tree based stuff. ๐ณ
- [`python-benedict`](https://github.com/fabiocaccamo/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`](https://github.com/fabiocaccamo/python-codicefiscale) - encode/decode Italian fiscal codes - codifica/decodifica del Codice Fiscale. ๐ฎ๐น ๐ณ
- [`python-fontbro`](https://github.com/fabiocaccamo/python-fontbro) - friendly font operations. ๐งข
- [`python-fsutil`](https://github.com/fabiocaccamo/python-fsutil) - file-system utilities for lazy devs. ๐งโโ๏ธ
Raw data
{
"_id": null,
"home_page": null,
"name": "django-colorfield",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": "Fabio Caccamo <fabio.caccamo@gmail.com>",
"keywords": "django, colorfield, colorpicker, color, field, picker, chooser, admin, python",
"author": null,
"author_email": "Jared Forsyth <jared@jaredforsyth.com>, Fabio Caccamo <fabio.caccamo@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/f5/c6/837e963e3fbf9919aac11b0433629261f6d34bf48dac31211430bdfdbb48/django_colorfield-0.12.0.tar.gz",
"platform": null,
"description": "[](https://www.python.org/)\n[](https://www.djangoproject.com/)\n\n[](https://pypi.org/project/django-colorfield/)\n[](https://pepy.tech/project/django-colorfield)\n[](https://github.com/fabiocaccamo/django-colorfield/stargazers)\n[](https://github.com/fabiocaccamo/django-colorfield/blob/main/LICENSE.txt)\n\n[](https://results.pre-commit.ci/latest/github/fabiocaccamo/django-colorfield/main)\n[](https://github.com/fabiocaccamo/django-colorfield)\n[](https://codecov.io/gh/fabiocaccamo/django-colorfield)\n[](https://www.codacy.com/app/fabiocaccamo/django-colorfield)\n[](https://codeclimate.com/github/fabiocaccamo/django-colorfield/)\n[](https://github.com/psf/black)\n[](https://github.com/astral-sh/ruff)\n\n# django-colorfield\nsimple color field for your models with a nice color-picker in the admin-interface.\n\n\n\n\n---\n\n## Installation\n- Run `pip install django-colorfield`\n- Add `colorfield` to `settings.INSTALLED_APPS`\n- Run `python manage.py collectstatic`\n- Restart your application server\n\n---\n\n## Usage\n\n### Settings\nThis package doesn't need any setting.\n\n### Models\nJust add color field(s) to your models like this:\n\n```python\nfrom colorfield.fields import ColorField\nfrom django.db import models\n\nclass MyModel(models.Model):\n color = ColorField(default='#FF0000')\n```\n\n### Field Options\nThese are the supported custom options: [`format`](#format), [`image_field`](#image_field), [`samples`](#samples)\n\n#### format\n\nThe following formats are supported: `hex` *(default)*, `hexa`, `rgb`, `rgba`.\n\n```python\nfrom colorfield.fields import ColorField\nfrom django.db import models\n\nclass MyModel(models.Model):\n color = ColorField(format=\"hexa\")\n```\n\n#### image_field\n\nIt is possible to auto-populate the field value getting the color from an image using the `image_field` option.\n\nThe color will be calculated from the **top-left pixel** color of the image each time the model instance is saved.\n\n```python\nfrom colorfield.fields import ColorField\nfrom django.db import models\n\nclass MyModel(models.Model):\n image = models.ImageField(upload_to=\"images\")\n color = ColorField(image_field=\"image\")\n```\n\n#### samples\n\nIt is possible to provide a palette of colors to choose from to the widget using the `samples` option.\n\nThis option **is not restrictive** (on the contrary of `choices` option), it is also possible to choose another color from the spectrum.\n\n\n\n```python\nfrom colorfield.fields import ColorField\nfrom django.db import models\n\nclass MyModel(models.Model):\n\n COLOR_PALETTE = [\n (\"#FFFFFF\", \"white\", ),\n (\"#000000\", \"black\", ),\n ]\n\n # not restrictive, allows the selection of another color from the spectrum.\n color = ColorField(samples=COLOR_PALETTE)\n\n # restrictive, it is mandatory to choose a color from the palette\n color = ColorField(choices=COLOR_PALETTE)\n```\n\n### Forms\n\n#### Model forms\n\nThe `colorfield.fields.ColorField` can be used in Django model forms (`django.forms.ModelForm`) to provide a color picker widget.\nWhen used in a model form, the field automatically validates the color format based on the specified `format` (e.g., `hex`, `rgb`, `rgba`).\n\n```python\nfrom django import forms\n\nclass MyModelForm(forms.ModelForm):\n class Meta:\n model = MyModel\n fields = [\"color\"]\n```\n\n#### Plain forms\n\nThe `colorfield.forms.ColorField` can be used in plain Django forms (`django.forms.Form`) to provide a color-picker widget.\nThis is useful when you need a color input outside of a model context.\n\n```python\nfrom django import forms\nfrom colorfield.forms import ColorField\n\nclass MyForm(forms.Form):\n color = ColorField(initial=\"#FF0000\", format=\"hex\")\n```\n\n### Admin\nThe admin will kindly provide a simple [color picker](http://jscolor.com/) for all color fields. :)\n\n---\n\n## Testing\n```bash\n# clone repository\ngit clone https://github.com/fabiocaccamo/django-colorfield.git && cd django-colorfield\n\n# create virtualenv and activate it\npython -m venv venv && . venv/bin/activate\n\n# upgrade pip\npython -m pip install --upgrade pip\n\n# install requirements\npip install -r requirements.txt -r requirements-test.txt\n\n# install pre-commit to run formatters and linters\npre-commit install --install-hooks\n\n# run tests\ntox\n# or\npython runtests.py\n# or\npython -m django test --settings \"tests.settings\"\n```\n---\n\n## Credits\nOriginally developed by [Jared Forsyth](https://github.com/jaredly)\n\n---\n\n## License\nReleased under [MIT License](LICENSE.txt).\n\n---\n\n## Supporting\n\n- :star: Star this project on [GitHub](https://github.com/fabiocaccamo/django-colorfield)\n- :octocat: Follow me on [GitHub](https://github.com/fabiocaccamo)\n- :blue_heart: Follow me on [Twitter](https://twitter.com/fabiocaccamo)\n- :moneybag: Sponsor me on [Github](https://github.com/sponsors/fabiocaccamo)\n\n## See also\n\n- [`django-admin-interface`](https://github.com/fabiocaccamo/django-admin-interface) - the default admin interface made customizable by the admin itself. popup windows replaced by modals. \ud83e\uddd9 \u26a1\n\n- [`django-cache-cleaner`](https://github.com/fabiocaccamo/django-cache-cleaner) - clear the entire cache or individual caches easily using the admin panel or management command. \ud83e\uddf9\u2728\n\n- [`django-extra-settings`](https://github.com/fabiocaccamo/django-extra-settings) - config and manage typed extra settings using just the django admin. \u2699\ufe0f\n\n- [`django-maintenance-mode`](https://github.com/fabiocaccamo/django-maintenance-mode) - shows a 503 error page when maintenance-mode is on. \ud83d\udea7 \ud83d\udee0\ufe0f\n\n- [`django-redirects`](https://github.com/fabiocaccamo/django-redirects) - redirects with full control. \u21aa\ufe0f\n\n- [`django-treenode`](https://github.com/fabiocaccamo/django-treenode) - probably the best abstract model / admin for your tree based stuff. \ud83c\udf33\n\n- [`python-benedict`](https://github.com/fabiocaccamo/python-benedict) - dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. \ud83d\udcd8\n\n- [`python-codicefiscale`](https://github.com/fabiocaccamo/python-codicefiscale) - encode/decode Italian fiscal codes - codifica/decodifica del Codice Fiscale. \ud83c\uddee\ud83c\uddf9 \ud83d\udcb3\n\n- [`python-fontbro`](https://github.com/fabiocaccamo/python-fontbro) - friendly font operations. \ud83e\udde2\n\n- [`python-fsutil`](https://github.com/fabiocaccamo/python-fsutil) - file-system utilities for lazy devs. \ud83e\udddf\u200d\u2642\ufe0f\n",
"bugtrack_url": null,
"license": "MIT License\n \n Copyright (c) 2013-present Jared Forsyth / Fabio Caccamo\n \n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n \n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n ",
"summary": "color field for django models with a nice color-picker in the admin.",
"version": "0.12.0",
"project_urls": {
"Documentation": "https://github.com/fabiocaccamo/django-colorfield#readme",
"Download": "https://github.com/fabiocaccamo/django-colorfield/releases",
"Funding": "https://github.com/sponsors/fabiocaccamo/",
"Homepage": "https://github.com/fabiocaccamo/django-colorfield",
"Issues": "https://github.com/fabiocaccamo/django-colorfield/issues",
"Twitter": "https://twitter.com/fabiocaccamo"
},
"split_keywords": [
"django",
" colorfield",
" colorpicker",
" color",
" field",
" picker",
" chooser",
" admin",
" python"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "6aba1c59fbacc298e20d84ac95f908529aed120c9fa9b17ec8be8851793f9b94",
"md5": "eb3a0d7b2ebe9228575fa8dec6c7a7f8",
"sha256": "ceb9a312e01773a0d609847eb308e3b81ac18c33874d17b2c7135a8d1b2ec86d"
},
"downloads": -1,
"filename": "django_colorfield-0.12.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "eb3a0d7b2ebe9228575fa8dec6c7a7f8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 53856,
"upload_time": "2025-01-27T18:30:12",
"upload_time_iso_8601": "2025-01-27T18:30:12.926390Z",
"url": "https://files.pythonhosted.org/packages/6a/ba/1c59fbacc298e20d84ac95f908529aed120c9fa9b17ec8be8851793f9b94/django_colorfield-0.12.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "f5c6837e963e3fbf9919aac11b0433629261f6d34bf48dac31211430bdfdbb48",
"md5": "fd802aeece1d3640d9a83b9aac186175",
"sha256": "9fbace0e3bf7126acab33daa52a5ae2fe0b339aeee30233f52bf911b685c0c71"
},
"downloads": -1,
"filename": "django_colorfield-0.12.0.tar.gz",
"has_sig": false,
"md5_digest": "fd802aeece1d3640d9a83b9aac186175",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 56444,
"upload_time": "2025-01-27T18:30:16",
"upload_time_iso_8601": "2025-01-27T18:30:16.186179Z",
"url": "https://files.pythonhosted.org/packages/f5/c6/837e963e3fbf9919aac11b0433629261f6d34bf48dac31211430bdfdbb48/django_colorfield-0.12.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-27 18:30:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "fabiocaccamo",
"github_project": "django-colorfield#readme",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "django",
"specs": [
[
">=",
"2.2"
]
]
},
{
"name": "Pillow",
"specs": [
[
">=",
"9.0.0"
]
]
}
],
"tox": true,
"lcname": "django-colorfield"
}