sigma_viewset.py 文件源码

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

项目:sigma-backend 作者: SRLKilling 项目源码 文件源码
def try_to_get(obj, pk):
        """
            This method can be used to get a model instance based on it's primary key.
            If the instance does not exists, it will automatically throws a 404 error.

            Method version : uses the queryset provided in the subclass definition
            Static version : takes the queryset to use as its first argument.
        """
        if isinstance(obj, SigmaViewSet):
            return SigmaViewSet.try_to_get(obj.__class__.queryset, pk)

        try:
            instance = obj.get(pk=pk)
        except obj.model.DoesNotExist:
            raise NotFound()

        return instance
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号