import_cards.py 文件源码

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

项目:django-magic-cards 作者: pbaranay 项目源码 文件源码
def get_or_create(self, model, field, value, **kwargs):
        """
        Retrieves object of class `model` with lookup key `value` from the cache. If not found,
        creates the object based on `field=value` and any other `kwargs`.

        Returns a tuple of `(object, created)`, where `created` is a boolean specifying whether an
        `object` was created.
        """
        result = self[model].get(value)
        created = False
        if not result:
            kwargs[field] = value
            result = model.objects.create(**kwargs)
            self[model][value] = result
            created = True
        return result, created
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号