

def annotate(self, rel_model, annotation=None):
    if (annotation is None):
        annotation = fn.Count(rel_model._meta.primary_key).alias('count')
    if (self._query_ctx == rel_model):
        query = self.switch(self.model_class)
    else:
        query = self.clone()
    query = query.ensure_join(query._query_ctx, rel_model)
    if (not query._group_by):
        query._group_by = [x.alias() for x in query._select]
    query._select = (tuple(query._select) + (annotation,))
    return query

dataset/ETHPy150Open coleifer/peewee/peewee.py SelectQuery.annotate/original