{"id":4503,"library":"django-colorfield","title":"Django Color Field","description":"django-colorfield is a simple color field for Django models, providing a user-friendly color-picker widget in the Django admin interface. It supports various color formats including HEX, HEXA, RGB, and RGBA. The library is actively maintained, with version 0.14.0 recently released, and typically sees updates for new Django and Python versions.","status":"active","version":"0.14.0","language":"en","source_language":"en","source_url":"https://github.com/fabiocaccamo/django-colorfield","tags":["django","color","field","admin","picker","form","widget"],"install":[{"cmd":"pip install django-colorfield","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core framework dependency. Supports Django >= 4.2 up to 5.2.","package":"Django"}],"imports":[{"note":"For defining a color field in Django models.","symbol":"ColorField","correct":"from colorfield.fields import ColorField"},{"note":"For using the color field in plain Django forms (non-model forms).","symbol":"ColorField","correct":"from colorfield.forms import ColorField"},{"note":"For direct use of the color picker widget in custom forms.","symbol":"ColorWidget","correct":"from colorfield.widgets import ColorWidget"}],"quickstart":{"code":"import os\nfrom django.db import models\nfrom colorfield.fields import ColorField\n\n# settings.py modification:\n# INSTALLED_APPS = [\n#     ...,\n#     'colorfield',\n#     ...,\n# ]\n# After adding 'colorfield' to INSTALLED_APPS, run 'python manage.py collectstatic'.\n\nclass Product(models.Model):\n    name = models.CharField(max_length=100)\n    # Default format is HEX\n    main_color = ColorField(default='#FFFFFF')\n    # Example with RGBA format\n    background_color = ColorField(format=\"hexa\", default='#000000FF')\n\n    def __str__(self):\n        return f\"{self.name} ({self.main_color})\"","lang":"python","description":"To quickly get started, install the package, add 'colorfield' to your `settings.INSTALLED_APPS`, and then define `ColorField`s in your Django models. After modifying `INSTALLED_APPS`, remember to run `python manage.py collectstatic` for the color picker to appear correctly in the admin. The `ColorField` automatically provides a color picker in the Django admin interface."},"warnings":[{"fix":"Review any custom JavaScript or CSS related to the color picker. Refer to the `coloris` documentation for its API and styling, and update your code accordingly.","message":"Version 0.14.0 replaced the underlying JavaScript color picker library from `jscolor` to `coloris`. If you had custom JavaScript or styling that directly interacted with `jscolor`, this will be a breaking change and require updates.","severity":"breaking","affected_versions":"0.14.0+"},{"fix":"Ensure your project runs on Python 3.8+ and Django 4.2+ (or newer compatible versions as per releases). Upgrade your Python and Django environments if necessary.","message":"Support for older Python and Django versions has been progressively dropped. Version 0.8.0 dropped Python < 3.8 and Django < 2.2. Version 0.9.0 dropped Django 2.2. Later versions (e.g., 0.13.0) added support for Django 5.2, indicating continued forward compatibility but no backward compatibility with very old versions.","severity":"breaking","affected_versions":"0.8.0+"},{"fix":"If you are upgrading from a version older than 0.10.1 and have existing `ColorField`s, ensure you run `makemigrations` and `migrate` after updating to reflect the new `max_length` in your database schema. Review any custom validation that assumes a `max_length` of 18.","message":"The `max_length` of the `ColorField` was increased from 18 to 25 in version 0.10.1 to properly accommodate new formats like RGBA. If you relied on the previous `max_length` for database schema or custom validation, this change might require a database migration or adjustment of your validation rules.","severity":"gotcha","affected_versions":"0.10.1+"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}