fields.py 文件源码

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

项目:django-modeltrans 作者: zostera 项目源码 文件源码
def as_sql(self, bare_lookup, fallback=True):
        '''
        Compose the sql lookup to get the value for this virtual field in a query.
        '''
        language = self.get_language()
        if language == DEFAULT_LANGUAGE:
            return self._localized_lookup(language, bare_lookup)

        if not fallback:
            i18n_lookup = self._localized_lookup(language, bare_lookup)
            return Cast(i18n_lookup, self.output_field())

        fallback_chain = get_fallback_chain(language)
        # first, add the current language to the list of lookups
        lookups = [self._localized_lookup(language, bare_lookup)]
        # and now, add the list of fallback languages to the lookup list
        for fallback_language in fallback_chain:
            lookups.append(
                self._localized_lookup(fallback_language, bare_lookup)
            )
        return Coalesce(*lookups, output_field=self.output_field())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号