models.py 文件源码

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

项目:mist.api 作者: mistio 项目源码 文件源码
def get_singleton(cls):
        """Return (and create if missing) the single Portal document"""
        try:
            portal = cls.objects.get()
            log.debug("Loaded portal info from db.")
        except me.DoesNotExist:
            log.info("No portal info found in db, will try to initialize.")
            try:
                portal = cls()
                portal.save()
                log.info("Initialized portal info.")
            except me.NotUniqueError:
                log.warning("Probable race condition while initializing "
                            "portal info, will try to reload.")
                portal = cls.objects.get()
                log.debug("Loaded portal info from db.")
        except me.MultipleObjectsReturned:
            log.error("Multiple Portal info found in database.")
            portal = cls.objects.first()
        return portal
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号