code: def query_by_action(cls, action, argument=None):
          
          query = cls.query.filter_by(action=action.value)
          argument = argument or getattr(action, 'argument', None)
          if argument is not None:
              query = query.filter(db.or_(
                  cls.argument == str(argument),
                  cls.argument.is_(None),
              ))
          else:
              query = query.filter(cls.argument.is_(None))
          return query
docs: Prepare query object with filtered action.
  
          :param action: The action to deny.
          :param argument: The action argument. If it's ``None`` then, if exists,
              the ``action.argument`` will be taken. In the worst case will be
              set as ``None``. (Default: ``None``)
          :returns: A query object.