summaryrefslogtreecommitdiffstats
path: root/agenda/customfields.py
blob: ce96efeb5576b0366a4fb3e93a343039366e8815 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# customfields.py

from django import forms
from django.conf import settings
from django.db import models
from django.template.loader import render_to_string



class ColorWidget(forms.Widget):
    class Media:
        js = [settings.ADMIN_MEDIA_PREFIX + "js/ColorPicker2.js"]
        
    def render(self, name, value, attrs=None):
        return render_to_string("agenda/color.html", locals())
        
class ColorField(models.CharField):
    def __init__(self, *args, **kwargs):
        kwargs['max_length'] = 10
        super(ColorField, self).__init__(*args, **kwargs)

    def formfield(self, **kwargs):
        defaults = {'widget': ColorWidget()}
        defaults.update(kwargs)
        return super(ColorField, self).formfield(**defaults)