Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @H@CHOICES = (('x', 'Choice x'), ('y', 'Choice y'))
- class MyWidget(MultiWidget):
- def __init__(self, attrs=None):
- widgets = (RadioSelect(choices=CHOICES, attrs=attrs),
- TextInput(attrs=attrs))
- super(MyWidget, self).__init__(widgets, attrs)
- def decompress(self, value):
- if value:
- return value
- return ['x', 'hello',]
- class MyField(MultiValueField):
- def __init__(self, *args, **kwargs):
- fields = (
- ChoiceField(choices=CHOICES),
- CharField(max_length=100))
- super(MyField, self).__init__(fields=fields, *args, **kwargs)
- def compress(self, data_list):
- if data_list:
- return [data_list[0], data_list[1]]
- return [None, None]
Advertisement
Add Comment
Please, Sign In to add comment