Provide color samples or restrict to choices
mainYou can provide a palette of colors to the widget using two different approaches:
samples(Non-restrictive): Displays a palette of colors for quick selection, but still allows the user to pick any other color from the spectrum.choices(Restrictive): Forces the user to choose exactly one of the colors provided in the palette.
Example palette format:
COLOR_PALETTE = [
("#FFFFFF", "white", ),
("#000000", "black", ),
]from colorfield.fields import ColorField
from django.db import models
class MyModel(models.Model):
COLOR_PALETTE = [
("#FFFFFF", "white", ),
("#000000", "black", ),
]
# Not restrictive: allows selection from spectrum
color = ColorField(samples=COLOR_PALETTE)
# Restrictive: mandatory to choose from palette
color = ColorField(choices=COLOR_PALETTE)