Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- name = ['a', 'b', 'c']
- for input_name in names:
- field = forms.CharField(widget=DimensionsWidget(dimensions), required=False)
- def wrapper(field_name):
- def clean_dimensions(self):
- """
- Dimensions field clean method
- """
- # field_name == 'c' - ALWAYS!! :(
- value = self[field_name].value()
- try:
- for i in value:
- int(i)
- except ValueError as e:
- raise ValidationError(self.error_messages['invalid_int'] + unicode(e))
- return clean_dimensions
- # monkey-patch the clean method for this field
- setattr(self, 'clean_' + input_name, types.MethodType(wrapper(input_name), self))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement