#29077: [Help] Why JSONField for MySql/MariaDB etc are not supported in Django?
------------------------------------------+------------------------
Reporter: Akhil Lawrence | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.0
Severity: Normal | Keywords: help
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
JSON format is widely used these days. Databases like
[MariaDB](https://mariadb.com/kb/en/library/json-data-type/),
[MySql](https://dev.mysql.com/doc/refman/5.7/en/json.html) etc supports
JSONField. But within Django, JSONField is only provided for the postgres.
Why is it so? Is there any reason for this?
Also irrespective of whether the DB supports JSON datatype or not, JSON
can be implemented by modifying TextField. And it believe it is very
helpful. Why don't we simply provide it? Many programmers I know, do their
custom implementation of JSONField on almost all their projects.
Something like this,
{{{
class JSONField(models.TextField):
""" JSON field implementation on top of django textfield """
def to_dict(self, value):
""" convert json string to python dictionary """
return json.loads(value)
def to_json(self, value):
""" convert python dictionary to json string """
return json.dumps(value)
def from_db_value(self, value, expression, connection):
""" convert string from db to python dictionary """
if value is None:
return value
return self.to_dict(value)
def to_python(self, value):
""" convert model input value to python dictionary """
if isinstance(value, dict):
return value
if value is None:
return value
return self.to_dict(value)
def get_prep_value(self, value):
""" convert python dictionary to string before writing to db """
return self.to_json(value)
}}}
Could you guys please clarify Django teams perspective on this.
--
Ticket URL: <https://code.djangoproject.com/ticket/29077>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/055.1615e26772ec9567881857fdb19dfad3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.