def test_order_by_two_virtual_fields(self):
ca = Category.objects.create(name='foo a', title='test a', title_nl='testje a')
cb = Category.objects.create(name='foo b', title='test b', title_nl='testje b')
Blog.objects.bulk_create([
Blog(title='a', title_nl='d', category=cb),
Blog(title='b', title_nl='c', category=cb),
Blog(title='c', title_nl='b', category=cb),
Blog(title='z', title_nl='a', category=ca),
Blog(title='y', title_nl='b', category=ca),
Blog(title='x', title_nl='c', category=ca)
])
qs = Blog.objects.filter(category__title_nl__contains='test').order_by(
'-category__title_nl',
'-title_nl'
)
self.assertEquals([m.title for m in qs], 'a b c x y z'.split())
评论列表
文章目录