def to_json(self, resource): ''' Builds JSON for resource according to fields attribute ''' if not resource: return elif is_relatedmanager(resource) or is_manyrelatedmanager(resource): return [self.to_json( i ) for i in resource.all()] return self.__fields_to_json( resource )
def __serialize(self, x): ''' Converts to JSON-serializable object ''' if is_serializable(x): return x elif is_geo_value(x): return json.loads(x.geojson) elif is_relatedmanager(x) or is_manyrelatedmanager(x): return [unicode(i) for i in x.all()] return unicode(x)