Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. class TakisField(forms.CharField):
  2.  
  3.     def validate(self, value):
  4.         import json
  5.         try:
  6.             s = json.dumps("{}".format(value))
  7.             j = json.loads(s)
  8.         except:
  9.             raise forms.ValidationError("Invalid StructuredValue field. Not a valid JSON")
  10.  
  11.     def to_python(self, value):
  12.         import json
  13.         try:
  14.             new_value = json.loads(value)
  15.         except:
  16.             raise forms.ValidationError("Invalid StructuredValue field. Not a valid JSON")
  17.         else:
  18.             return new_value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement