summaryrefslogtreecommitdiffstats
path: root/agenda/customfields.py
diff options
context:
space:
mode:
Diffstat (limited to 'agenda/customfields.py')
-rwxr-xr-xagenda/customfields.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/agenda/customfields.py b/agenda/customfields.py
new file mode 100755
index 0000000..ce96efe
--- /dev/null
+++ b/agenda/customfields.py
@@ -0,0 +1,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)
+