models.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:statik 作者: thanethomson 项目源码 文件源码
def find_additional_rels(self, all_models):
        """Attempts to scan for additional relationship fields for this model based on all of the other models'
        structures and relationships.
        """
        for model_name, model in iteritems(all_models):
            if model_name != self.name:
                for field_name in model.field_names:
                    field = model.fields[field_name]
                    # if this field type references the current model
                    if field.field_type == self.name and field.back_populates is not None and \
                            (isinstance(field, StatikForeignKeyField) or isinstance(field, StatikManyToManyField)):
                        self.additional_rels[field.back_populates] = {
                            'to_model': model_name,
                            'back_populates': field_name,
                            'secondary':
                                (model_name, field.field_type) if isinstance(field, StatikManyToManyField) else None
                        }
                        logger.debug('Additional relationship %s.%s -> %s (%s)' % (
                            self.name,
                            field.back_populates,
                            model_name,
                            self.additional_rels[field.back_populates]
                        ))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号