- signals.post_init.connect(self.post_init, sender=cls)
-
- def get_json(model_instance):
- return dumps(getattr(model_instance, self.attname, None))
- setattr(cls, 'get_%s_json' % self.name, get_json)
-
- def set_json(model_instance, json):
- return setattr(model_instance, self.attname, loads(json))
- setattr(cls, 'set_%s_json' % self.name, set_json)
-
- def post_init(self, **kwargs):
- instance = kwargs.get('instance', None)
- value = self.value_from_object(instance)
- if (value):
- setattr(instance, self.attname, loads(value))
- else:
- setattr(instance, self.attname, None)
+
+ def get_value(model_instance):
+ return loads(getattr(model_instance, self.attname, None))
+ setattr(cls, 'get_%s_value' % self.name, get_value)
+
+ def set_value(model_instance, json):
+ return setattr(model_instance, self.attname, dumps(json))
+ setattr(cls, 'set_%s_value' % self.name, set_value)