

def related_models(self, backrefs=False):
    models = []
    stack = [self.model_class]
    while stack:
        model = stack.pop()
        if (model in models):
            continue
        models.append(model)
        for fk in model._meta.rel.values():
            stack.append(fk.rel_model)
        if stack:
            for fk in model._meta.reverse_rel.values():
                stack.append(fk.model_class)
    return models

dataset/ETHPy150Open coleifer/peewee/peewee.py ModelOptions.related_models/VarMisuse@85/94 `backrefs`->`stack`