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


Python Article.get_previous_by_pub_date方法代码示例

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


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

示例1: LookupTests

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_previous_by_pub_date [as 别名]

#.........这里部分代码省略.........
             (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
        # 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>',
            ])
        self.assertQuerysetEqual(
开发者ID:arceduardvincent,项目名称:mongodb-engine,代码行数:70,代码来源:tests.py

示例2: LookupTests

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_previous_by_pub_date [as 别名]

#.........这里部分代码省略.........
            [
                (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))
        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>',
            ])
        self.assertQuerysetEqual(Article.objects.filter(headline__startswith='Article_'),
                                 ['<Article: Article_ with underscore>'])
        a9 = Article(headline='Article% with percent sign', pub_date=datetime(2005, 11, 21))
        a9.save()
开发者ID:chadcatlett,项目名称:django,代码行数:70,代码来源:tests.py

示例3: LookupTests

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_previous_by_pub_date [as 别名]

#.........这里部分代码省略.........
        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>",
            ],
        )
        self.assertQuerysetEqual(
            Article.objects.filter(headline__startswith="Article_"), ["<Article: Article_ with underscore>"]
        )
        a9 = Article(headline="Article% with percent sign", pub_date=datetime(2005, 11, 21))
        a9.save()
        self.assertQuerysetEqual(
            Article.objects.filter(headline__startswith="Article"),
            [
开发者ID:JWW81,项目名称:stochss,代码行数:70,代码来源:tests.py


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