本文整理汇总了Python中models.Article.get_next_by_pub_date方法的典型用法代码示例。如果您正苦于以下问题:Python Article.get_next_by_pub_date方法的具体用法?Python Article.get_next_by_pub_date怎么用?Python Article.get_next_by_pub_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Article
的用法示例。
在下文中一共展示了Article.get_next_by_pub_date方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LookupTests
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_next_by_pub_date [as 别名]
#.........这里部分代码省略.........
# dictionaries. Within each tuple, the order of the elements is
# the same as the order of fields in the values_list() call.
identity = lambda x: x
self.assertQuerysetEqual(
Article.objects.values_list('headline'),
[
(u'Article 5',),
(u'Article 6',),
(u'Article 4',),
(u'Article 2',),
(u'Article 3',),
(u'Article 7',),
(u'Article 1',),
], transform=identity)
self.assertQuerysetEqual(
Article.objects.values_list('id').order_by('id'),
[(self.a1.id,), (self.a2.id,), (self.a3.id,), (self.a4.id,),
(self.a5.id,), (self.a6.id,), (self.a7.id,)],
transform=identity)
self.assertQuerysetEqual(
Article.objects.values_list('id', flat=True).order_by('id'),
[self.a1.id, self.a2.id, self.a3.id, self.a4.id, self.a5.id,
self.a6.id, self.a7.id],
transform=identity)
self.assertRaises(TypeError, Article.objects.values_list, 'id',
'headline', flat=True)
def test_get_next_previous_by(self):
# Every DateField and DateTimeField creates get_next_by_FOO()
# and get_previous_by_FOO() methods. In the case of identical
# date values, these methods will use the ID as a fallback
# check. This guarantees that no records are skipped or
# duplicated.
self.assertEqual(repr(self.a1.get_next_by_pub_date()),
'<Article: Article 2>')
self.assertEqual(repr(self.a2.get_next_by_pub_date()),
'<Article: Article 3>')
self.assertEqual(
repr(self.a2.get_next_by_pub_date(headline__endswith='6')),
'<Article: Article 6>')
self.assertEqual(repr(self.a3.get_next_by_pub_date()),
'<Article: Article 7>')
self.assertEqual(repr(self.a4.get_next_by_pub_date()),
'<Article: Article 6>')
self.assertRaises(Article.DoesNotExist, self.a5.get_next_by_pub_date)
self.assertEqual(repr(self.a6.get_next_by_pub_date()),
'<Article: Article 5>')
self.assertEqual(repr(self.a7.get_next_by_pub_date()),
'<Article: Article 4>')
self.assertEqual(repr(self.a7.get_previous_by_pub_date()),
'<Article: Article 3>')
self.assertEqual(repr(self.a6.get_previous_by_pub_date()),
'<Article: Article 4>')
self.assertEqual(repr(self.a5.get_previous_by_pub_date()),
'<Article: Article 6>')
self.assertEqual(repr(self.a4.get_previous_by_pub_date()),
'<Article: Article 7>')
self.assertEqual(repr(self.a3.get_previous_by_pub_date()),
'<Article: Article 2>')
self.assertEqual(repr(self.a2.get_previous_by_pub_date()),
'<Article: Article 1>')
def test_escaping(self):
# Underscores, percent signs and backslashes have special
# meaning in the underlying SQL code, but Django handles
示例2: LookupTests
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_next_by_pub_date [as 别名]
#.........这里部分代码省略.........
self.assertQuerysetEqual(
Article.objects.extra(select={'id_plus_one': 'id+1'})
.order_by('id').values_list('id_plus_one', 'id'),
[
(self.a1.id+1, self.a1.id),
(self.a2.id+1, self.a2.id),
(self.a3.id+1, self.a3.id),
(self.a4.id+1, self.a4.id),
(self.a5.id+1, self.a5.id),
(self.a6.id+1, self.a6.id),
(self.a7.id+1, self.a7.id)
],
transform=identity)
self.assertQuerysetEqual(
Article.objects.extra(select={'id_plus_one': 'id+1'})
.order_by('id').values_list('id', 'id_plus_one'),
[
(self.a1.id, self.a1.id+1),
(self.a2.id, self.a2.id+1),
(self.a3.id, self.a3.id+1),
(self.a4.id, self.a4.id+1),
(self.a5.id, self.a5.id+1),
(self.a6.id, self.a6.id+1),
(self.a7.id, self.a7.id+1)
],
transform=identity)
self.assertRaises(TypeError, Article.objects.values_list, 'id', 'headline', flat=True)
def test_get_next_previous_by(self):
# Every DateField and DateTimeField creates get_next_by_FOO() and
# get_previous_by_FOO() methods. In the case of identical date values,
# these methods will use the ID as a fallback check. This guarantees
# that no records are skipped or duplicated.
self.assertEqual(repr(self.a1.get_next_by_pub_date()),
'<Article: Article 2>')
self.assertEqual(repr(self.a2.get_next_by_pub_date()),
'<Article: Article 3>')
self.assertEqual(repr(self.a2.get_next_by_pub_date(headline__endswith='6')),
'<Article: Article 6>')
self.assertEqual(repr(self.a3.get_next_by_pub_date()),
'<Article: Article 7>')
self.assertEqual(repr(self.a4.get_next_by_pub_date()),
'<Article: Article 6>')
self.assertRaises(Article.DoesNotExist, self.a5.get_next_by_pub_date)
self.assertEqual(repr(self.a6.get_next_by_pub_date()),
'<Article: Article 5>')
self.assertEqual(repr(self.a7.get_next_by_pub_date()),
'<Article: Article 4>')
self.assertEqual(repr(self.a7.get_previous_by_pub_date()),
'<Article: Article 3>')
self.assertEqual(repr(self.a6.get_previous_by_pub_date()),
'<Article: Article 4>')
self.assertEqual(repr(self.a5.get_previous_by_pub_date()),
'<Article: Article 6>')
self.assertEqual(repr(self.a4.get_previous_by_pub_date()),
'<Article: Article 7>')
self.assertEqual(repr(self.a3.get_previous_by_pub_date()),
'<Article: Article 2>')
self.assertEqual(repr(self.a2.get_previous_by_pub_date()),
'<Article: Article 1>')
def test_escaping(self):
# Underscores, percent signs and backslashes have special meaning in the
# underlying SQL code, but Django handles the quoting of them automatically.
a8 = Article(headline='Article_ with underscore', pub_date=datetime(2005, 11, 20))
示例3: LookupTests
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_next_by_pub_date [as 别名]
#.........这里部分代码省略.........
(self.a2.id, self.a2.id + 1),
(self.a3.id, self.a3.id + 1),
(self.a4.id, self.a4.id + 1),
(self.a5.id, self.a5.id + 1),
(self.a6.id, self.a6.id + 1),
(self.a7.id, self.a7.id + 1),
],
transform=identity,
)
self.assertQuerysetEqual(
Author.objects.values_list("name", "article__headline", "article__tag__name").order_by(
"name", "article__headline", "article__tag__name"
),
[
(self.au1.name, self.a1.headline, self.t1.name),
(self.au1.name, self.a2.headline, self.t1.name),
(self.au1.name, self.a3.headline, self.t1.name),
(self.au1.name, self.a3.headline, self.t2.name),
(self.au1.name, self.a4.headline, self.t2.name),
(self.au2.name, self.a5.headline, self.t2.name),
(self.au2.name, self.a5.headline, self.t3.name),
(self.au2.name, self.a6.headline, self.t3.name),
(self.au2.name, self.a7.headline, self.t3.name),
],
transform=identity,
)
self.assertRaises(TypeError, Article.objects.values_list, "id", "headline", flat=True)
def test_get_next_previous_by(self):
# Every DateField and DateTimeField creates get_next_by_FOO() and
# get_previous_by_FOO() methods. In the case of identical date values,
# these methods will use the ID as a fallback check. This guarantees
# that no records are skipped or duplicated.
self.assertEqual(repr(self.a1.get_next_by_pub_date()), "<Article: Article 2>")
self.assertEqual(repr(self.a2.get_next_by_pub_date()), "<Article: Article 3>")
self.assertEqual(repr(self.a2.get_next_by_pub_date(headline__endswith="6")), "<Article: Article 6>")
self.assertEqual(repr(self.a3.get_next_by_pub_date()), "<Article: Article 7>")
self.assertEqual(repr(self.a4.get_next_by_pub_date()), "<Article: Article 6>")
self.assertRaises(Article.DoesNotExist, self.a5.get_next_by_pub_date)
self.assertEqual(repr(self.a6.get_next_by_pub_date()), "<Article: Article 5>")
self.assertEqual(repr(self.a7.get_next_by_pub_date()), "<Article: Article 4>")
self.assertEqual(repr(self.a7.get_previous_by_pub_date()), "<Article: Article 3>")
self.assertEqual(repr(self.a6.get_previous_by_pub_date()), "<Article: Article 4>")
self.assertEqual(repr(self.a5.get_previous_by_pub_date()), "<Article: Article 6>")
self.assertEqual(repr(self.a4.get_previous_by_pub_date()), "<Article: Article 7>")
self.assertEqual(repr(self.a3.get_previous_by_pub_date()), "<Article: Article 2>")
self.assertEqual(repr(self.a2.get_previous_by_pub_date()), "<Article: Article 1>")
def test_escaping(self):
# Underscores, percent signs and backslashes have special meaning in the
# underlying SQL code, but Django handles the quoting of them automatically.
a8 = Article(headline="Article_ with underscore", pub_date=datetime(2005, 11, 20))
a8.save()
self.assertQuerysetEqual(
Article.objects.filter(headline__startswith="Article"),
[
"<Article: Article_ with underscore>",
"<Article: Article 5>",
"<Article: Article 6>",
"<Article: Article 4>",
"<Article: Article 2>",
"<Article: Article 3>",
"<Article: Article 7>",
"<Article: Article 1>",
],