<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def query_by_action(cls, action, argument=None):
 """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. """

        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