Python django.shortcuts 模块,_get_queryset() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用django.shortcuts._get_queryset()

项目:pontifex-project    作者:PontifexProject    | 项目源码 | 文件源码
def get_object_or_403(klass, *args, **kwargs):
    """
    Uses get() to return an object, or raises a PermissionDenied exception if the object
    does not exist.

    klass may be a Model, Manager, or QuerySet object. All other passed
    arguments and keyword arguments are used in the get() query.

    Note: Like with get(), an MultipleObjectsReturned will be raised if more than one
    object is found.
    """
    queryset = _get_queryset(klass)
    try:
        return queryset.get(*args, **kwargs)
    except queryset.model.DoesNotExist:
        raise PermissionDenied
项目:planet-b-saleor    作者:planet-b    | 项目源码 | 文件源码
def get_object_or_none(klass, *args, **kwargs):
    queryset = _get_queryset(klass)
    try:
        return queryset.get(*args, **kwargs)
    except AttributeError:
        klass__name = klass.__name__ if isinstance(klass, type) else klass.__class__.__name__
        raise ValueError(
            "First argument to get_object_or_none() must be a Model, Manager, "
            "or QuerySet, not '%s'." % klass__name
        )
    except queryset.model.DoesNotExist:
        return None
项目:the-contract-site    作者:shadytradesman    | 项目源码 | 文件源码
def get_queryset_size(klass,  *args, **kwargs):
    queryset = _get_queryset(klass)
    try:
        obj_list = list(queryset.filter(*args, **kwargs))
    except AttributeError:
        klass__name = klass.__name__ if isinstance(klass, type) else klass.__class__.__name__
        raise ValueError(
            "First argument get_queryset_size() must be a Model, Manager, or "
            "QuerySet, not '%s'." % klass__name
        )
    if not obj_list:
        return 0
    return len(obj_list)
项目:the-contract-site    作者:shadytradesman    | 项目源码 | 文件源码
def get_object_or_none(klass, *args, **kwargs):
    queryset = _get_queryset(klass)
    try:
        return queryset.get(*args, **kwargs)
    except AttributeError:
        klass__name = klass.__name__ if isinstance(klass, type) else klass.__class__.__name__
        raise ValueError(
            "First argument to get_object_or_none() must be a Model, Manager, "
            "or QuerySet, not '%s'." % klass__name
        )
    except queryset.model.DoesNotExist:
        return None
项目:django_mc    作者:team23    | 项目源码 | 文件源码
def __init__(self, model_or_qs):
        self.queryset = _get_queryset(model_or_qs)
        self.model = self.queryset.model