<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def group_by(self, field=None, table=None, allow_duplicates=False):
 """ Adds a group by clause to the query by adding a ``Group`` instance to the query's groups list :type field: str or dict or :class:`Field <querybuilder.fields.Field>` :param field: This can be a string of a field name, a dict of {'alias': field}, or a ``Field`` instance :type table: str or dict or :class:`Table <querybuilder.table.Table>` :param table: Optional. This can be a string of a table name, a dict of {'alias': table}, or a ``Table`` instance. A table only needs to be supplied in more complex queries where the field name is ambiguous. :return: self :rtype: :class:`Query <querybuilder.query.Query>` """

        new_group_item = Group(
            field=field,
            table=table,
        )

        if allow_duplicates is False:
            for group_item in self.groups:
                if group_item.field.get_identifier() == new_group_item.field.get_identifier():
                    return self

        self.groups.append(new_group_item)

        return self