manager.py 文件源码

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

项目:django-modeltrans 作者: zostera 项目源码 文件源码
def _get_field(self, lookup):
        '''
        Return the Django model field for a lookup plus the remainder of the lookup,
        which should be the lookup type.
        '''
        field = None
        lookup_type = None

        bits = lookup.split(LOOKUP_SEP)

        model = self.model
        for i, bit in enumerate(bits):
            try:
                field = model._meta.get_field(bit)
            except FieldDoesNotExist:
                lookup_type = LOOKUP_SEP.join(bits[i:])
                break

            if hasattr(field, 'remote_field'):
                rel = getattr(field, 'remote_field', None)
                model = getattr(rel, 'model', model)

        return field, lookup_type
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号