-
- def todict (self):
- d=self.__dict__
- keys=[k for k in d.keys() if not k.startswith('_')]
- return dict ( [ (k,d[k]) for k in keys ] )
-
+
+ #
+ # need to filter out results, esp. wrt relationships
+ # exclude_types must be a tuple so we can use isinstance
+ #
+ def record_to_dict(self, exclude_types=None):
+ if exclude_types is None:
+ exclude_types = ()
+ d = self.__dict__
+
+ def exclude(k, v):
+ return k.startswith('_') or isinstance(v, exclude_types)
+ keys = [k for k, v in d.items() if not exclude(k, v)]
+ return {k: d[k] for k in keys}
+