# =============================================================================
# yourapp/widgets.py
# =============================================================================

from django import forms
from django.conf import settings
from django.utils.safestring import mark_safe

class ColorPickerWidget(forms.TextInput):
    class Media:
        css = {
            'all': (
                settings.MEDIA_URL + 'cssjs/colorPicker.css',
            )
        }
        js = (
            'http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js',
            settings.MEDIA_URL + 'cssjs/jquery.colorPicker.js',
        )

    def __init__(self, language=None, attrs=None):
        self.language = language or settings.LANGUAGE_CODE[:2]
        super(ColorPickerWidget, self).__init__(attrs=attrs)

    def render(self, name, value, attrs=None):
        rendered = super(ColorPickerWidget, self).render(name, value, attrs)
        return rendered + mark_safe(u'''<script type="text/javascript">
            $('#id_%s').colorPicker();
            </script>''' % name)


# =============================================================================
# yourapp/models.py
# =============================================================================

from yourapp.widgets import ColorPickerWidget

class ColorField(models.CharField):
    def __init__(self, *args, **kwargs):
        kwargs['max_length'] = 10
        super(ColorField, self).__init__(*args, **kwargs)

    def formfield(self, **kwargs):
        kwargs['widget'] = ColorPickerWidget
        return super(ColorField, self).formfield(**kwargs)


class YourModel(models.Model):
    # ...
    font_color = ColorField(blank=True) 
    # ...


# =============================================================================
# static/cssjs/colorPicker.css
# =============================================================================

/*
    see: http://github.com/laktek/really-simple-color-picker/tree/master/colorPicker.css

    To render nicely in the Django admin I added these lines to the bottom:
*/

.form-row div .color_picker {
float:left;
}