Skip to content

Model and form fields to store RGB colors as hex strings and widget to render the native HTML5 color input element

License

Notifications You must be signed in to change notification settings

der-gabe/django-colorinput

Repository files navigation

django-colorinput

Color fields for forms and models using HTML5's native input element of type color.

Quickstart

Install django-colorinput and add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    …
    'colorinput.apps.ColorInputConfig',
    …
)

Now you can use ColorField in your models:

from django.db import models

from colorinput.models import ColorField

class MyModel(models.Model):
    …
    color = ColorField(default="d0d0d0")
    …

In forms, the color field will be displayed using HTML5's native color type input element. In your own templates, you could use the value stored in the field like this:

<span style="color: #{{ object.color }}">

… or however you want, really. Just keep in mind that the value is stored as RGB in triple HEX format without the leading "#" (hash symbol).

About

Model and form fields to store RGB colors as hex strings and widget to render the native HTML5 color input element

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published