Skip to content

Instantly share code, notes, and snippets.

@iolloyd
Created January 30, 2013 12:44
Show Gist options
  • Save iolloyd/4673048 to your computer and use it in GitHub Desktop.
Save iolloyd/4673048 to your computer and use it in GitHub Desktop.
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
@iolloyd
Copy link
Author

iolloyd commented Jan 30, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment