@classmethod
def register_model_query_hook(cls, model, name, query_hook, filter_hook,
    result_filters=None):
    """Register a hook to be invoked when a query is executed.

        Add the hooks to the _model_query_hooks dict. Models are the keys
        of this dict, whereas the value is another dict mapping hook names to
        callables performing the hook.
        Each hook has a "query" component, used to build the query expression
        and a "filter" component, which is used to build the filter expression.

        Query hooks take as input the query being built and return a
        transformed query expression.

        Filter hooks take as input the filter expression being built and return
        a transformed filter expression
        """
    model_hooks = cls._model_query_hooks.get(model)
    if not model_hooks:
        model_hooks = {}
        cls._model_query_hooks[model] = model_hooks
    model_hooks[name] = {'query': query_hook, 'filter': filter_hook,
        'result_filters': result_filters}
