code: def attach_events(*args):
      
      def wrapper(cls):
          for name, fn in cls.__dict__.items():
              if not name.startswith('__') and hasattr(fn, _SQLAlchemyEvent.ATTR):
                  e = getattr(fn, _SQLAlchemyEvent.ATTR)
                  if e.field_name:
                      event.listen(getattr(cls, e.field_name), e.event_name, fn,
                                   **e.listen_kwargs)
                  else:
                      event.listen(cls, e.event_name, fn, **e.listen_kwargs)
          return cls
      if args and callable(args[0]):
          return wrapper(args[0])
      return wrapper
docs: Class decorator for SQLAlchemy models to attach listeners on class
      methods decorated with :func:`.on`
  
      Usage::
  
          @attach_events
          class User(Model):
              email = Column(String(50))
  
              @on('email', 'set')
              def lowercase_email(self, new_value, old_value, initiating_event):
                  self.email = new_value.lower()