#12990: New Field Type: JSONField -------------------------------------+------------------------------------- Reporter: paltman | Owner: nobody Type: New | Status: new feature | Component: Database layer Milestone: | (models, ORM) Version: 1.2-beta | Severity: Normal Resolution: | Keywords: Triage Stage: Design | Has patch: 1 decision needed | Needs tests: 1 Needs documentation: 0 | Easy pickings: 0 Patch needs improvement: 1 | -------------------------------------+-------------------------------------
Comment (by Fredde): Replying to [comment:4 Alex]: > How are most of them wrong? It's pretty trivial (there's actually an implementation in the tests). The JSONField included in the in the django tests ([source:django/trunk/tests/modeltests/field_subclassing/fields.py#L56]) is actually not working properly eather. For example, when trying to store a empty list [] or dict {} the ''JSONField.to_python'' will convert it to None: {{{ #python >>> class A(models.Model): json_field = JSONField() >>> a = A() >>> a.json_field = [] >>> print a.json_fied None }}} I don't know how to fix this. From the documentation the following values should be handled by the ''to_python'' method: * An instance of the correct type (e.g., Hand in our ongoing example). * A string (e.g., from a deserializer). * Whatever the database returns for the column type you're using. Hovever, there is no way to know if the value is a "correct type" a serialized representation or the value from the database. For example value = '[1, 2, 3]'. It could eather come from an attribute assignment, or from the database, but it should only be deserialized if it's from the database. -- Ticket URL: <https://code.djangoproject.com/ticket/12990#comment:26> 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.