code: def enable_counter(self, base=None, database='counter',
                         collection='counters'):
          
          Counter._database_ = database
          Counter._collection_ = collection
          bases = (base, Counter) if base else (Counter,)
          counter = self.register_model(type('Counter', bases, {}))
  
          class CounterMixin(object):
              """Mixin class for model"""
              @classmethod
              def inc_counter(cls):
                  """Wrapper for ``Counter.increase()``."""
                  return counter.increase(cls._collection_)
  
              @classmethod
              def dec_counter(cls):
                  """Wrapper for ``Counter.decrease()``."""
                  return counter.decrease(cls._collection_)
  
              @classmethod
              def chg_counter(cls, *args, **kwargs):
                  """Wrapper for ``Counter.change_by()``."""
                  return counter.change_by(cls._collection_, *args, **kwargs)
  
              @classmethod
              def set_counter(cls, *args, **kwargs):
                  """Wrapper for ``Counter.set_to()``."""
                  return counter.set_to(cls._collection_, *args, **kwargs)
  
              def on_save(self, old_dict):
                  super(CounterMixin, self).on_save(old_dict)
                  if not old_dict.get('_id'):
                      counter.increase(self._collection_)
  
              def on_delete(self, *args, **kwargs):
                  super(CounterMixin, self).on_delete(*args, **kwargs)
                  counter.decrease(self._collection_)
  
              @classmethod
              def count(cls):
                  """Return the current count of this collection."""
                  return counter.count(cls._collection_)
  
          logging.info('Counter enabled on: %s' % counter.collection)
          return counter, CounterMixin
docs: Register the builtin counter model, return the registered Counter
          class and the corresponding ``CounterMixin`` class.
  
          The ``CounterMixin`` automatically increases and decreases the counter
          after model creation(save without ``_id``) and deletion.
  
          It contains a classmethod ``count()`` which returns the current count
          of the model collection.