MultiWidget, value_from_datadict, SplitDateWidget

61 views
Skip to first unread message

l5x

unread,
Dec 13, 2007, 12:05:10 PM12/13/07
to Django users
Hello,

Based on this thread: http://groups.google.com/group/django-users/browse_thread/thread/fd450734295e450f/68d466b0d6b24eb7

I have the following code for the SplitDateWidget:

class SplitDateWidget(forms.MultiWidget):
def __init__(self, attrs=None):
widgets = (Select(attrs=attrs, choices=DAY_LIST),
Select(attrs=attrs, choices=MONTH_LIST), Select(attrs=attrs,
choices=YEAR_LIST))
super(SplitDateWidget, self).__init__(widgets, attrs)

def value_from_datadict(self, data, files, name):
return [widget.value_from_datadict(data, files, name + '_
%s' % i) for i, widget in enumerate(self.widgets)]

def decompress(self, value):
if value:
print 'value: ', value
value=unicode(value).split('-')
return [value[2],value[1],value[0]]
return None

And I don't know what do I need to change in value_from_datadict to
get this work after request.POST. As for now I get error: "Ensure this
value has at most 3 characters (it has 22)."

oli...@obeattie.com

unread,
Dec 13, 2007, 3:15:39 PM12/13/07
to Django users
Doesn't Django have something very similar inbuilt to newforms?

l5x

unread,
Dec 13, 2007, 3:33:10 PM12/13/07
to Django users
> Doesn't Django have something very similar inbuilt to newforms?

You mean: SplitDateTimeWidget
But there is no custom 'value_from_datadict'
See: http://code.djangoproject.com/browser/django/trunk/django/newforms/widgets.py#L459

oli...@obeattie.com

unread,
Dec 13, 2007, 3:57:09 PM12/13/07
to Django users

l5x

unread,
Dec 14, 2007, 6:00:34 AM12/14/07
to Django users
No problem, just waiting for somebody more advanced than me to help
me:)
Reply all
Reply to author
Forward
0 new messages