from django import forms
from django.forms import widgets
class DateSelectorWidget(widgets.MultiWidget):
def __init__(self, attrs=None):
_widgets = (forms.TextInput(),
forms.TextInput())
super(DateSelectorWidget, self).__init__(_widgets, attrs)
def format_output(self, rendered_widgets):
return ''.join(rendered_widgets)
class Fourteen(forms.Form):
mywidget = DateSelectorWidget()
>>> fourteen = Fourteen()>>> print(fourteen)
>>>I’m not that familiar with MultiWidget, but it would seem that your print statement should be:
print(fourteen.mywidget)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
django-users...@googlegroups.com.
To post to this group, send email to
django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/86bebdb4-1d45-4612-84d1-456f86942709%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/86bebdb4-1d45-4612-84d1-456f86942709%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/hUmvw-mdaiY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ebd9f58fca3a4009abcfd05e16fca9dc%40ISS1.ISS.LOCAL.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to djang...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/86bebdb4-1d45-4612-84d1-456f86942709%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/hUmvw-mdaiY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
class ComplexMultiWidget(forms.MultiWidget):
def __init__(self, attrs=None):
widgets = (
forms.DateInput(),
forms.Select(choices=(('D', 'Days'),
('W', 'Weeks'),
('Y', 'Years'))),
)
super(ComplexMultiWidget, self).__init__(widgets, attrs)
def decompress(self, value):
if value:
data = value.split(',')
return [data[0], data[1]]
return [None, None, None]
def format_output(self, rendered_widgets):
return u'\n'.join(rendered_widgets)
class ComplexField(forms.MultiValueField):
def __init__(self, required=True, widget=None, label=None, initial=None):
fields = (
forms.DateField(widget=forms.DateInput),
forms.ChoiceField(choices=(('D', 'Days'),
('W', 'Weeks'),
('Y', 'Years'))),
)
super(ComplexField, self).__init__(fields, required,
widget, label, initial)
def compress(self, data_list):
if data_list:
return '%s,%s' % (data_list[0],''.join(data_list[1]))
return None
class ComplexFieldForm(forms.Form):
field1 = ComplexField(widget=ComplexMultiWidget())