#12990: New Field Type: JSONField -------------------------------------+------------------------------------- Reporter: paltman | Owner: nobody Type: New feature | Status: new Component: Database layer | Version: 1.2-alpha (models, ORM) | Resolution: Severity: Normal | Triage Stage: Design Keywords: | decision needed Has patch: 1 | Needs documentation: 0 Needs tests: 1 | Patch needs improvement: 1 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by riccardodivirgilio):
* version: 1.2-beta => 1.2-alpha Comment: this is my proposition to for the field. {{{ class JsonField(models.Field): __metaclass__ = models.SubfieldBase serialize_to_string = True def get_internal_type(self): return "TextField" def value_to_string(self, obj): return self.get_prep_value(self._get_val_from_obj(obj)) def get_prep_value(self, value): if value: stream = StringIO.StringIO() simplejson.dump(value, stream, cls=DjangoJSONEncoder) value = stream.getvalue() stream.close() return value return None def to_python(self, value): if isinstance(value, (str, unicode)): value = StringIO.StringIO(value) return simplejson.load(value) return value }}} maybe there is no need to to create a class JSONDateEncoder(json.JSONEncoder) because there is DjangoJSONEncoder already. then it would be great to implement a lazy translation object for DjangoJSONEncoder to store ugettext_lazy objects. for me there is no need to create set_%s_json and get_%s_json method because the field should handle it directly, and we should use the to_python method, like all other fields in django. for example the datetime field directly push a datetime object to the model (using to_python) and transform it to a string when save method is called we should use the same logic here and encode a json object to string only when we call the save method, no need for a get_%s_json in the field api. -- Ticket URL: <https://code.djangoproject.com/ticket/12990#comment:35> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.