本文整理汇总了Python中eulexistdb.query.QuerySet.exclude方法的典型用法代码示例。如果您正苦于以下问题:Python QuerySet.exclude方法的具体用法?Python QuerySet.exclude怎么用?Python QuerySet.exclude使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eulexistdb.query.QuerySet
的用法示例。
在下文中一共展示了QuerySet.exclude方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ExistQueryTest
# 需要导入模块: from eulexistdb.query import QuerySet [as 别名]
# 或者: from eulexistdb.query.QuerySet import exclude [as 别名]
#.........这里部分代码省略.........
.only('id', 'document_name').order_by('document_name')
self.assertEqual(
2, fqs.count(),
"should get 2 matches for filter on document name in list (got %s)" % fqs.count())
self.assertEqual('f1.xml', fqs[0].document_name)
fqs = self.qs.filter(document_name__in=['f1.xml', 'f2.xml']) \
.also('id', 'document_name').order_by('document_name')
self.assertEqual(
2, fqs.count(),
"should get 2 matches for filter on document name in list (got %s)" % fqs.count())
self.assertEqual('f1.xml', fqs[0].document_name)
def test_filter_exists(self):
fqs = self.qs.filter(id__exists=True)
self.assertEqual(4, fqs.count(),
"filter on id exists=true returns all documents")
fqs = self.qs.filter(id__exists=False)
self.assertEqual(0, fqs.count(),
"filter on id exists=false returns no documents")
fqs = self.qs.filter(wnn__exists=False)
self.assertEqual(3, fqs.count(),
"filter on wacky node name exists=false returns 3 documents")
def test_or_filter(self):
fqs = self.qs.or_filter(id='abc', name='four').only('id')
self.assertEqual(
2, fqs.count(),
"should get 2 matches for OR filter on id='abc' or name='four' (got %s)" % fqs.count())
ids = [obj.id for obj in fqs.all()]
self.assert_('abc' in ids, 'id "abc" in list of ids when OR filter includes id="abc"')
self.assert_('def' in ids, 'id "def" in list of ids when OR filter includes name="four')
def test_exclude(self):
fqs = self.qs.exclude(id='abc', name='one').only('id')
self.assertEqual(
2, fqs.count(),
"should get 2 matches for exclude filter on id='abc' or name='one' (got %s)" % fqs.count())
ids = [obj.id for obj in fqs.all()]
self.assert_('abc' not in ids, 'id "abc" should not be in list of ids when exclude id="abc"')
def test_filter_gtelte(self):
# < <= > >=
# subclass to add a numeric field to test with
class CountQueryTestModel(QueryTestModel):
name_count = xmlmap.IntegerField('count(name)')
qs = QuerySet(using=self.db, xpath='/root', collection=COLLECTION,
model=CountQueryTestModel)
# each fixture has one and only one name
self.assertEqual(0, qs.filter(name_count__gt=1).count())
self.assertEqual(4, qs.filter(name_count__gte=1).count())
self.assertEqual(4, qs.filter(name_count__lte=1).count())
self.assertEqual(0, qs.filter(name_count__lt=1).count())
def test_filter_document_path(self):
# get full test path to first document
item = self.qs.filter(name='one').only('document_name', 'collection_name').get()
path = '%s/%s' % (item.collection_name, item.document_name)
#
fqs = self.qs.filter(document_path=path, name='one')
self.assertEqual(1, fqs.count())
fqs = self.qs.filter(document_path=path, name='two')