Задать вопрос

Тел: +7 965 3737 888

482

Просмотров

1

Ответов

models ColorField with clean minimal widget

A simple model ColorField that allows picking from a predefined list (currently picked up from settings.py

The widget displays as a row of coloured SPAN's with the hex code inside. Simply click to choose a color.

(requires jQuery in the page assigned to it's normal $ shortcut. Easy to change this is you don't use jQuery in this way)

Вопрос полезен? Да0/Нет0
file_4371.py(1.7Кб)
None

Ответы (1):

Ответbadrihippo:30.08.2013
Ответ полезен? Да0/Нет0

You can also extend it to give names to the colours.

First, make COLORPICKER_COLORS into a dictionary, something like this :

COLORPICKER_COLORS = {
    'ff0000': 'red',
    '00ff00': 'green',
    '0000ff': 'blue',
    'ffffff': 'white',
    '000000': 'black'
}

Then , in color_widget.html, replace {% for color in colors %} with {% for color, colname in colors.items %}, and make the content of the span {{ colname }} instead of {{ color }}.