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


Python ModelAdmin.inlines方法代码示例

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


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

示例1: test_custom_min_num

# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import inlines [as 别名]
    def test_custom_min_num(self):
        bt_head = BinaryTree.objects.create(name="Tree Head")
        BinaryTree.objects.create(name="First Child", parent=bt_head)

        class MinNumInline(TabularInline):
            model = BinaryTree
            extra = 3

            def get_min_num(self, request, obj=None, **kwargs):
                if obj:
                    return 5
                return 2

        modeladmin = ModelAdmin(BinaryTree, admin_site)
        modeladmin.inlines = [MinNumInline]
        min_forms = (
            '<input id="id_binarytree_set-MIN_NUM_FORMS" '
            'name="binarytree_set-MIN_NUM_FORMS" type="hidden" value="%d">'
        )
        total_forms = (
            '<input id="id_binarytree_set-TOTAL_FORMS" '
            'name="binarytree_set-TOTAL_FORMS" type="hidden" value="%d">'
        )
        request = self.factory.get(reverse('admin:admin_inlines_binarytree_add'))
        request.user = User(username='super', is_superuser=True)
        response = modeladmin.changeform_view(request)
        self.assertInHTML(min_forms % 2, response.rendered_content)
        self.assertInHTML(total_forms % 5, response.rendered_content)

        request = self.factory.get(reverse('admin:admin_inlines_binarytree_change', args=(bt_head.id,)))
        request.user = User(username='super', is_superuser=True)
        response = modeladmin.changeform_view(request, object_id=str(bt_head.id))
        self.assertInHTML(min_forms % 5, response.rendered_content)
        self.assertInHTML(total_forms % 8, response.rendered_content)
开发者ID:berabhishek,项目名称:django,代码行数:36,代码来源:tests.py

示例2: test_custom_min_num

# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import inlines [as 别名]
    def test_custom_min_num(self):
        """
        Ensure that get_min_num is called and used correctly.
        """
        bt_head = BinaryTree.objects.create(name="Tree Head")
        BinaryTree.objects.create(name="First Child", parent=bt_head)

        class MinNumInline(TabularInline):
            model = BinaryTree
            extra = 3

            def get_min_num(self, request, obj=None, **kwargs):
                if obj:
                    return 5
                return 2

        modeladmin = ModelAdmin(BinaryTree, admin_site)
        modeladmin.inlines = [MinNumInline]

        min_forms = '<input id="id_binarytree_set-MIN_NUM_FORMS" name="binarytree_set-MIN_NUM_FORMS" type="hidden" value="%d" />'
        total_forms = '<input id="id_binarytree_set-TOTAL_FORMS" name="binarytree_set-TOTAL_FORMS" type="hidden" value="%d" />'

        request = self.factory.get('/admin/admin_inlines/binarytree/add/')
        request.user = User(username='super', is_superuser=True)
        response = modeladmin.changeform_view(request)
        self.assertContains(response, min_forms % 2)
        self.assertContains(response, total_forms % 5)

        request = self.factory.get("/admin/admin_inlines/binarytree/%d/" % bt_head.id)
        request.user = User(username='super', is_superuser=True)
        response = modeladmin.changeform_view(request, object_id=str(bt_head.id))
        self.assertContains(response, min_forms % 5)
        self.assertContains(response, total_forms % 8)
开发者ID:986425391,项目名称:django,代码行数:35,代码来源:tests.py

示例3: test_min_num

# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import inlines [as 别名]
    def test_min_num(self):
        """
        Ensure that min_num and extra determine number of forms.
        """

        class MinNumInline(TabularInline):
            model = BinaryTree
            min_num = 2
            extra = 3

        modeladmin = ModelAdmin(BinaryTree, admin_site)
        modeladmin.inlines = [MinNumInline]

        min_forms = (
            '<input id="id_binarytree_set-MIN_NUM_FORMS" name="binarytree_set-MIN_NUM_FORMS" type="hidden" value="2" />'
        )
        total_forms = (
            '<input id="id_binarytree_set-TOTAL_FORMS" name="binarytree_set-TOTAL_FORMS" type="hidden" value="5" />'
        )

        request = self.factory.get(reverse("admin:admin_inlines_binarytree_add"))
        request.user = User(username="super", is_superuser=True)
        response = modeladmin.changeform_view(request)
        self.assertContains(response, min_forms)
        self.assertContains(response, total_forms)
开发者ID:HouseAlwaysWin,项目名称:django,代码行数:27,代码来源:tests.py

示例4: test_min_num

# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import inlines [as 别名]
    def test_min_num(self):
        """
        min_num and extra determine number of forms.
        """
        class MinNumInline(TabularInline):
            model = BinaryTree
            min_num = 2
            extra = 3

        modeladmin = ModelAdmin(BinaryTree, admin_site)
        modeladmin.inlines = [MinNumInline]
        min_forms = (
            '<input id="id_binarytree_set-MIN_NUM_FORMS" '
            'name="binarytree_set-MIN_NUM_FORMS" type="hidden" value="2">'
        )
        total_forms = (
            '<input id="id_binarytree_set-TOTAL_FORMS" '
            'name="binarytree_set-TOTAL_FORMS" type="hidden" value="5">'
        )
        request = self.factory.get(reverse('admin:admin_inlines_binarytree_add'))
        request.user = User(username='super', is_superuser=True)
        response = modeladmin.changeform_view(request)
        self.assertInHTML(min_forms, response.rendered_content)
        self.assertInHTML(total_forms, response.rendered_content)
开发者ID:berabhishek,项目名称:django,代码行数:26,代码来源:tests.py


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