<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def namespace(self, namespace, to=None):
 """ Filter by namespace. Try to guess which field to use in lookup. Accept 'to' argument if you need to specify. """

        fields = get_apphook_field_names(self.model)
        if not fields:
            raise ValueError(
                ugettext(
                    'Can\'t find any relation to an ApphookConfig model in {0}'
                ).format(self.model.__name__)
            )
        if to and to not in fields:
            raise ValueError(
                ugettext(
                    'Can\'t find relation to ApphookConfig model named '
                    '"{0}" in "{1}"'
                ).format(to, self.model.__name__)
            )
        if len(fields) > 1 and to not in fields:
            raise ValueError(
                ugettext(
                    '"{0}" has {1} relations to an ApphookConfig model.'
                    ' Please, specify which one to use in argument "to".'
                    ' Choices are: {2}'
                ).format(
                    self.model.__name__, len(fields), ', '.join(fields)
                )
            )
        else:
            if not to:
                to = fields[0]

        lookup = '{0}__namespace'.format(to)
        kwargs = {lookup: namespace}
        return self.filter(**kwargs)