Created
January 30, 2013 12:44
-
-
Save iolloyd/4673048 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
def to_json(self, view='list_view'): | |
out = {} | |
for f in self.get_fields(view): | |
field_value = getattr(self, f) | |
if hasattr(f, 'to_json'): | |
out[f] = field_value.to_json(view) # relation object | |
elif hasattr(f, 'isoformat'): | |
out[f] = field_value.isoformat() # datetime object | |
else: | |
out[f] = field_value | |
return out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a method in the base class that all the models inherit from. Can't work out why the to_json method isn't found when it encounters a model object.