Skip to content

Commit

Permalink
add JSONField definition
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkukral committed Oct 2, 2017
1 parent 80655c3 commit 7373e26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions kqueen/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask.json import JSONEncoder


class CustomJSONEncoder(JSONEncoder):
def default(self, obj):

Expand Down
16 changes: 16 additions & 0 deletions kqueen/storages/etcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ class IdField(Field):
pass


class JSONField(Field):
"""JSON is stored as value"""

def set_value(self, value):
if isinstance(value, str):
self.value = json.loads(value)
elif isinstance(value, dict):
self.value = value

def serialize(self):
if self.value and isinstance(self.value, dict):
return json.dumps(self.value)
else:
return None


db = EtcdOrm()

# TODO: implement required fields
Expand Down

0 comments on commit 7373e26

Please sign in to comment.