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


Python ModelAdmin.get_changelist_instance方法代码示例

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


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

示例1: test_choice_links

# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import get_changelist_instance [as 别名]
    def test_choice_links(self):
        modeladmin = ModelAdmin(Question, site)
        modeladmin.date_hierarchy = 'posted'

        posted_dates = (
            datetime.date(2017, 10, 1),
            datetime.date(2017, 10, 1),
            datetime.date(2017, 12, 15),
            datetime.date(2017, 12, 15),
            datetime.date(2017, 12, 31),
            datetime.date(2018, 2, 1),
        )
        Question.objects.bulk_create(Question(question='q', posted=posted) for posted in posted_dates)

        tests = (
            ({}, [['year=2017'], ['year=2018']]),
            ({'year': 2016}, []),
            ({'year': 2017}, [['month=10', 'year=2017'], ['month=12', 'year=2017']]),
            ({'year': 2017, 'month': 9}, []),
            ({'year': 2017, 'month': 12}, [['day=15', 'month=12', 'year=2017'], ['day=31', 'month=12', 'year=2017']]),
        )
        for query, expected_choices in tests:
            with self.subTest(query=query):
                query = {'posted__%s' % q: val for q, val in query.items()}
                request = self.factory.get('/', query)
                changelist = modeladmin.get_changelist_instance(request)
                spec = date_hierarchy(changelist)
                choices = [choice['link'] for choice in spec['choices']]
                expected_choices = [
                    '&'.join('posted__%s' % c for c in choice) for choice in expected_choices
                ]
                expected_choices = [('?' + choice) if choice else '' for choice in expected_choices]
                self.assertEqual(choices, expected_choices)
开发者ID:CodeMonk,项目名称:django,代码行数:35,代码来源:test_templatetags.py


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