MCPcopy
hub / github.com/django/django / to_python

Method to_python

django/contrib/postgres/forms/hstore.py:26–49  ·  view source on GitHub ↗
(self, value)

Source from the content-addressed store, hash-verified

24 return value
25
26 def to_python(self, value):
27 if not value:
28 return {}
29 if not isinstance(value, dict):
30 try:
31 value = json.loads(value)
32 except json.JSONDecodeError:
33 raise ValidationError(
34 self.error_messages["invalid_json"],
35 code="invalid_json",
36 )
37
38 if not isinstance(value, dict):
39 raise ValidationError(
40 self.error_messages["invalid_format"],
41 code="invalid_format",
42 )
43
44 # Cast everything to strings for ease.
45 for key, val in value.items():
46 if val is not None:
47 val = str(val)
48 value[key] = val
49 return value
50
51 def has_changed(self, initial, data):
52 """

Callers 1

has_changedMethod · 0.95

Calls 3

ValidationErrorClass · 0.90
loadsMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected