Simple json/yaml export of Model instances.
Signed-off-by: Adam Stokes <adam.stokes@ubuntu.com>
This commit is contained in:
parent
4588a52ebf
commit
8db1a34501
|
@ -19,21 +19,22 @@ Model's represent the stateful data bound from
|
|||
input from the user.
|
||||
"""
|
||||
|
||||
import json
|
||||
import yaml
|
||||
|
||||
|
||||
class Model:
|
||||
"""Base model"""
|
||||
|
||||
fields = []
|
||||
|
||||
@classmethod
|
||||
def to_json(cls):
|
||||
def to_json(self):
|
||||
"""Marshals the model to json"""
|
||||
raise NotImplementedError
|
||||
return json.dumps(self.__dict__)
|
||||
|
||||
@classmethod
|
||||
def to_yaml(cls):
|
||||
def to_yaml(self):
|
||||
"""Marshals the model to yaml"""
|
||||
raise NotImplementedError
|
||||
return yaml.dump(self.__dict__)
|
||||
|
||||
|
||||
class Field:
|
||||
|
|
Loading…
Reference in New Issue