当前位置: 首页>>代码示例>>Python>>正文


Python query.EmptyQuerySet方法代码示例

本文整理汇总了Python中django.db.models.query.EmptyQuerySet方法的典型用法代码示例。如果您正苦于以下问题:Python query.EmptyQuerySet方法的具体用法?Python query.EmptyQuerySet怎么用?Python query.EmptyQuerySet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.models.query的用法示例。


在下文中一共展示了query.EmptyQuerySet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_and

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def test_and(self):
        """ANDing with a QuerySet applies the and to each QuerySet and removes ones of differing types."""
        # ANDing with a different type of QuerySet ends up with an EmptyQuerySet.
        with self.assertNumQueries(0):
            combined = self.all & BlogPost.objects.all()
        self.assertIsInstance(combined, EmptyQuerySet)

        # ANDing with a QuerySet of a type in the QuerySetSequence applies the
        # AND to that QuerySet.
        with self.assertNumQueries(0):
            combined = self.all & Book.objects.filter(pages__lt=15)
        self.assertIsInstance(combined, QuerySetSequence)
        self.assertEqual(len(combined._querysets), 1)
        with self.assertNumQueries(1):
            data = [it.title for it in combined.iterator()]
        self.assertEqual(data, ['Fiction']) 
开发者ID:percipient,项目名称:django-querysetsequence,代码行数:18,代码来源:test_querysetsequence.py

示例2: __and__

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def __and__(self, other):
        # If the other QuerySet is an EmptyQuerySet, this is a no-op.
        if isinstance(other, EmptyQuerySet):
            return other
        combined = self._clone()

        querysets = []
        for qs in combined._querysets:
            # Only QuerySets of the same type can have any overlap.
            if issubclass(qs.model, other.model):
                querysets.append(qs & other)

        # If none are left, we're left with an EmptyQuerySet.
        if not querysets:
            return other.none()

        combined._set_querysets(querysets)
        return combined 
开发者ID:percipient,项目名称:django-querysetsequence,代码行数:20,代码来源:__init__.py

示例3: filter

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def filter(self, *args, **kwargs):
        """
        Returns a new QuerySetSequence or instance with the args ANDed to the
        existing set.

        QuerySetSequence is simplified thus result actually can be one of:
        QuerySetSequence, QuerySet, EmptyQuerySet.
        """
        return self._filter_or_exclude(False, *args, **kwargs) 
开发者ID:certsocietegenerale,项目名称:FIR,代码行数:11,代码来源:querysets.py

示例4: exclude

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def exclude(self, *args, **kwargs):
        """
        Returns a new QuerySetSequence instance with NOT (args) ANDed to the
        existing set.

        QuerySetSequence is simplified thus result actually can be one of:
        QuerySetSequence, QuerySet, EmptyQuerySet.
        """
        return self._filter_or_exclude(True, *args, **kwargs) 
开发者ID:certsocietegenerale,项目名称:FIR,代码行数:11,代码来源:querysets.py

示例5: _simplify

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def _simplify(self, qss=None):
        '''
        Returns QuerySetSequence, QuerySet or EmptyQuerySet depending on the
        contents of items, i.e. at least two non empty QuerySets, exactly one
        non empty QuerySet and all empty QuerySets respectively.

        Does not modify original QuerySetSequence.
        '''
        not_empty_qss = filter(None, qss if qss else self.iables)
        if not len(not_empty_qss):
            return EmptyQuerySet()
        if len(not_empty_qss) == 1:
            return not_empty_qss[0]
        return QuerySetSequence(*not_empty_qss) 
开发者ID:certsocietegenerale,项目名称:FIR,代码行数:16,代码来源:querysets.py

示例6: test_and_identity

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def test_and_identity(self):
        """ANDing with an EmptyQuerySet returns an EmptyQuerySet."""
        with self.assertNumQueries(0):
            combined = self.all & BlogPost.objects.none()
        self.assertIsInstance(combined, EmptyQuerySet) 
开发者ID:percipient,项目名称:django-querysetsequence,代码行数:7,代码来源:test_querysetsequence.py

示例7: test_empty_and

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def test_empty_and(self):
        """An empty QuerySetSequence can be ANDed with a QuerySet, but returns an EmptyQuerySet."""
        combined = self.empty & BlogPost.objects.all()
        self.assertIsInstance(combined, EmptyQuerySet)
        self.assertEqual(list(combined), []) 
开发者ID:percipient,项目名称:django-querysetsequence,代码行数:7,代码来源:test_querysetsequence.py

示例8: test_empty_or

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def test_empty_or(self):
        """An empty QuerySetSequence can be ORed with a QuerySet, but returns an EmptyQuerySet."""
        combined = self.empty | BlogPost.objects.all()
        self.assertIsInstance(combined, QuerySetSequence)
        self.assertEqual(len(combined._querysets), 1)

        with self.assertNumQueries(1):
            data = [it.title for it in combined.iterator()]
        self.assertEqual(data, ['Post']) 
开发者ID:percipient,项目名称:django-querysetsequence,代码行数:11,代码来源:test_querysetsequence.py

示例9: test_none

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def test_none(self):
        """
        Ensure an instance of EmptyQuerySet is returned and has no results (and
        doesn't perform queries).
        """
        with self.assertNumQueries(0):
            qss = self.all.none()
            data = list(qss)

        # This returns an EmptyQuerySet.
        self.assertIsInstance(qss, EmptyQuerySet)

        # Should have no data.
        self.assertEqual(data, []) 
开发者ID:percipient,项目名称:django-querysetsequence,代码行数:16,代码来源:test_querysetsequence.py

示例10: __or__

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def __or__(self, other):
        # If the other QuerySet is an EmptyQuerySet, this is a no-op.
        if isinstance(other, EmptyQuerySet):
            return self
        combined = self._clone()

        # If the other instance is a QuerySetSequence, combine the QuerySets.
        if isinstance(other, QuerySetSequence):
            combined._set_querysets(self._querysets + other._querysets)

        elif isinstance(other, QuerySet):
            combined._set_querysets(self._querysets + [other])

        return combined 
开发者ID:percipient,项目名称:django-querysetsequence,代码行数:16,代码来源:__init__.py

示例11: none

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def none(self):
        # This is a bit odd, but use the first QuerySet to properly return an
        # that is an instance of EmptyQuerySet.
        return self._querysets[0].none() 
开发者ID:percipient,项目名称:django-querysetsequence,代码行数:6,代码来源:__init__.py

示例12: get_empty_query_set

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def get_empty_query_set(self):
        return EmptyQuerySet(self.model, using=self._db) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:4,代码来源:manager.py

示例13: test_model_multiple_choice_required_false

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def test_model_multiple_choice_required_false(self):
        f = forms.ModelMultipleChoiceField(Category.objects.all(), required=False)
        self.assertIsInstance(f.clean([]), EmptyQuerySet)
        self.assertIsInstance(f.clean(()), EmptyQuerySet)
        with self.assertRaises(ValidationError):
            f.clean(['0'])
        with self.assertRaises(ValidationError):
            f.clean([str(self.c3.id), '0'])
        with self.assertRaises(ValidationError):
            f.clean([str(self.c1.id), '0'])

        # queryset can be changed after the field is created.
        f.queryset = Category.objects.exclude(name='Third')
        self.assertEqual(list(f.choices), [
            (self.c1.pk, 'Entertainment'),
            (self.c2.pk, "It's a test")])
        self.assertQuerysetEqual(f.clean([self.c2.id]), ["It's a test"])
        with self.assertRaises(ValidationError):
            f.clean([self.c3.id])
        with self.assertRaises(ValidationError):
            f.clean([str(self.c2.id), str(self.c3.id)])

        f.queryset = Category.objects.all()
        f.label_from_instance = lambda obj: "multicategory " + str(obj)
        self.assertEqual(list(f.choices), [
            (self.c1.pk, 'multicategory Entertainment'),
            (self.c2.pk, "multicategory It's a test"),
            (self.c3.pk, 'multicategory Third')]) 
开发者ID:nesdis,项目名称:djongo,代码行数:30,代码来源:tests.py

示例14: test_emptyqs

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def test_emptyqs(self):
        msg = "EmptyQuerySet can't be instantiated"
        with self.assertRaisesMessage(TypeError, msg):
            EmptyQuerySet()
        self.assertIsInstance(Article.objects.none(), EmptyQuerySet)
        self.assertNotIsInstance('', EmptyQuerySet) 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:tests.py

示例15: test_emptyqs_values

# 需要导入模块: from django.db.models import query [as 别名]
# 或者: from django.db.models.query import EmptyQuerySet [as 别名]
def test_emptyqs_values(self):
        # test for #15959
        Article.objects.create(headline='foo', pub_date=datetime.now())
        with self.assertNumQueries(0):
            qs = Article.objects.none().values_list('pk')
            self.assertIsInstance(qs, EmptyQuerySet)
            self.assertEqual(len(qs), 0) 
开发者ID:nesdis,项目名称:djongo,代码行数:9,代码来源:tests.py


注:本文中的django.db.models.query.EmptyQuerySet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。