Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TakisField(forms.CharField):
- def validate(self, value):
- import json
- try:
- s = json.dumps("{}".format(value))
- j = json.loads(s)
- except:
- raise forms.ValidationError("Invalid StructuredValue field. Not a valid JSON")
- def to_python(self, value):
- import json
- try:
- new_value = json.loads(value)
- except:
- raise forms.ValidationError("Invalid StructuredValue field. Not a valid JSON")
- else:
- return new_value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement