

def dependencies(self, search_nullable=False):
    model_class = type(self)
    query = self.select().where(self._pk_expr())
    stack = [(type(self), query)]
    seen = set()
    while stack:
        (klass, query) = stack.pop()
        if (klass in seen):
            continue
        seen.add(klass)
        for (rel_name, fk) in klass._meta.reverse_rel.items():
            rel_model = fk.model_class
            if (fk.rel_model is model_class):
                node = (fk == self._data[fk.to_field.name])
                subquery = rel_model.select().where(node)
            else:
                node = (fk << query)
                subquery = rel_model.select().where(node)
            if ((not fk.null) or search_nullable):
                stack.append((rel_model, subquery))
            (yield (node, fk))

dataset/ETHPy150Open coleifer/peewee/peewee.py Model.dependencies/original