Created
January 25, 2016 17:57
-
-
Save samirbr/3d1f73f9d867d11fe665 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
import json | |
class JSONField(models.TextField): | |
def __init__(self, verbose_name=None, name=None, default=None, **kwargs): | |
models.TextField.__init__(self, verbose_name, name, **kwargs) | |
def to_python(self, value): | |
if isinstance(value, six.string_types) or value is None: | |
return value | |
return json.loads(value) | |
def value_to_string(self, obj): | |
self.value_from_object(json.dumps(obj)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment