Commits

Jesper Nøhr  committed faafc8c

Allow callable defined in models to be used as fields for model-based Handler, fixes #35, thanks ack

  • Participants
  • Parent commits b0a1571

Comments (0)

Files changed (1)

File piston/emitters.py

                         if inst:
                             if hasattr(inst, 'all'):
                                 ret[model] = _related(inst, fields)
+                            elif callable(inst):
+                                if len(inspect.getargspec(inst)[0]) == 1:
+                                    ret[model] = _any(inst(), fields)
                             else:
                                 ret[model] = _model(inst, fields)
 
                         if maybe:
                             if isinstance(maybe, (int, basestring)):
                                 ret[maybe_field] = _any(maybe)
+                            elif callable(maybe):
+                                if len(inspect.getargspec(maybe)[0]) == 1:
+                                    ret[maybe_field] = _any(maybe())
                         else:
                             handler_f = getattr(handler or self.handler, maybe_field, None)