views.py 文件源码

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

项目:nav 作者: UNINETT 项目源码 文件源码
def is_valid_field(self, model, field):
        """
        Return true if the field exists within the model (or in the related
        model specified using the Django ORM __ notation)
        """
        components = field.split('__', 1)
        try:
            field, _parent_model, _direct, _m2m = \
                model._meta.get_field_by_name(components[0])

            # reverse relation
            if isinstance(field, _RelatedObject):
                return self.is_valid_field(field.model, components[1])

            # foreign key
            if field.rel and len(components) == 2:
                return self.is_valid_field(field.rel.to, components[1])
            return True
        except FieldDoesNotExist:
            return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号