本文整理汇总了Python中eulexistdb.query.QuerySet.order_by_raw方法的典型用法代码示例。如果您正苦于以下问题:Python QuerySet.order_by_raw方法的具体用法?Python QuerySet.order_by_raw怎么用?Python QuerySet.order_by_raw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eulexistdb.query.QuerySet
的用法示例。
在下文中一共展示了QuerySet.order_by_raw方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ExistQueryTest
# 需要导入模块: from eulexistdb.query import QuerySet [as 别名]
# 或者: from eulexistdb.query.QuerySet import order_by_raw [as 别名]
#.........这里部分代码省略.........
self.assertEqual(NUM_FIXTURES, self.qs.count(), "main queryset remains unchanged by filter")
def test_order_by(self):
# element
fqs = self.qs.order_by('name')
self.assertEqual('four', fqs[0].name)
self.assertEqual('one', fqs[1].name)
self.assertEqual('three', fqs[2].name)
self.assertEqual('two', fqs[3].name)
self.assert_('order by ' not in self.qs.query.getQuery(), "main queryset unchanged by order_by()")
# attribute
fqs = self.qs.order_by('id')
self.assertEqual('abc', fqs[0].id)
self.assertEqual('def', fqs[1].id)
self.assertEqual('one', fqs[2].id)
self.assertEqual('xyz', fqs[3].id)
# reverse sorting
fqs = self.qs.order_by('-name')
self.assertEqual('four', fqs[3].name)
self.assertEqual('two', fqs[0].name)
fqs = self.qs.order_by('-id')
self.assertEqual('abc', fqs[3].id)
self.assertEqual('xyz', fqs[0].id)
# case-insensitive sorting - upper-case description should not sort first
fqs = self.qs.order_by('~description')
self.assert_(fqs[0].description.startswith('third'))
self.assert_(fqs[1].description.startswith('This one contains'))
# reverse case-insensitive sorting - flags in either order
fqs = self.qs.order_by('~-description')
self.assert_(fqs[3].description.startswith('third'))
fqs = self.qs.order_by('-~description')
self.assert_(fqs[3].description.startswith('third'))
def test_order_by_raw(self):
fqs = self.qs.order_by_raw('min(%(xq_var)s/year)')
self.assert_('1990' in fqs[0].years)
self.assert_('2001' in fqs[1].years)
self.assert_('2010' in fqs[2].years)
self.assertEqual([], fqs[3].years)
fqs = self.qs.order_by_raw('min(%(xq_var)s/year)', ascending=False)
self.assertEqual([], fqs[0].years)
self.assert_('2010' in fqs[1].years)
self.assert_('2001' in fqs[2].years)
self.assert_('1990' in fqs[3].years)
def test_only(self):
self.qs.only('name')
self.assert_('element name {' not in self.qs.query.getQuery(), "main queryset unchanged by only()")
fqs = self.qs.filter(id='one').only('name', 'id', 'sub', 'or_field')
self.assert_(isinstance(fqs[0], QueryTestModel)) # actually a Partial type derived from this
# attributes that should be present
self.assertNotEqual(fqs[0].id, None)
self.assertNotEqual(fqs[0].sub, None)
self.assertNotEqual(fqs[0].sub.subname, None)
self.assertNotEqual(fqs[0].or_field, None)
# attribute not returned
self.assertEqual(fqs[0].description, None)
self.assertEqual('one', fqs[0].id)
self.assertEqual('one', fqs[0].name)
self.assertEqual('la', fqs[0].sub.subname)
self.assertEqual('one', fqs[0].or_field) # = name (first of ORed fields present)
fqs = self.qs.filter(id='one').only('wnn')
self.assertTrue(hasattr(fqs[0], "wnn"))