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


Python admin.TabularInline方法代码示例

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


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

示例1: test_exclude_in_inline

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import TabularInline [as 别名]
def test_exclude_in_inline(self):
        class ExcludedFieldsInline(admin.TabularInline):
            model = Song
            exclude = 'foo'

        class ExcludedFieldsAlbumAdmin(admin.ModelAdmin):
            model = Album
            inlines = [ExcludedFieldsInline]

        errors = ExcludedFieldsAlbumAdmin(Album, AdminSite()).check()
        expected = [
            checks.Error(
                "The value of 'exclude' must be a list or tuple.",
                obj=ExcludedFieldsInline,
                id='admin.E014',
            )
        ]
        self.assertEqual(errors, expected) 
开发者ID:nesdis,项目名称:djongo,代码行数:20,代码来源:tests.py

示例2: test_fk_exclusion

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import TabularInline [as 别名]
def test_fk_exclusion(self):
        """
        Regression test for #11709 - when testing for fk excluding (when exclude is
        given) make sure fk_name is honored or things blow up when there is more
        than one fk to the parent model.
        """
        class TwoAlbumFKAndAnEInline(admin.TabularInline):
            model = TwoAlbumFKAndAnE
            exclude = ("e",)
            fk_name = "album1"

        class MyAdmin(admin.ModelAdmin):
            inlines = [TwoAlbumFKAndAnEInline]

        errors = MyAdmin(Album, AdminSite()).check()
        self.assertEqual(errors, []) 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:tests.py

示例3: test_inline_self_check

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import TabularInline [as 别名]
def test_inline_self_check(self):
        class TwoAlbumFKAndAnEInline(admin.TabularInline):
            model = TwoAlbumFKAndAnE

        class MyAdmin(admin.ModelAdmin):
            inlines = [TwoAlbumFKAndAnEInline]

        errors = MyAdmin(Album, AdminSite()).check()
        expected = [
            checks.Error(
                "'admin_checks.TwoAlbumFKAndAnE' has more than one ForeignKey to 'admin_checks.Album'.",
                obj=TwoAlbumFKAndAnEInline,
                id='admin.E202',
            )
        ]
        self.assertEqual(errors, expected) 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:tests.py

示例4: test_min_num

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import TabularInline [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:nesdis,项目名称:djongo,代码行数:26,代码来源:tests.py

示例5: test_tabularmodel_admin

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import TabularInline [as 别名]
def test_tabularmodel_admin(cls):
        """Tests whether :see:LocalizedFieldsAdminMixin mixin are works with
        admin.TabularInline."""

        class TestModelTabularInline(
            LocalizedFieldsAdminMixin, admin.TabularInline
        ):
            model = cls.TestModel

        @admin.register(cls.TestRelModel)
        class TestRelModelAdmin(admin.ModelAdmin):
            inlines = [TestModelTabularInline]

        assert len(check_admin_app(apps.get_app_configs())) == 0 
开发者ID:SectorLabs,项目名称:django-localized-fields,代码行数:16,代码来源:test_admin.py

示例6: test_inline_with_specified

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import TabularInline [as 别名]
def test_inline_with_specified(self):
        class TwoAlbumFKAndAnEInline(admin.TabularInline):
            model = TwoAlbumFKAndAnE
            fk_name = "album1"

        class MyAdmin(admin.ModelAdmin):
            inlines = [TwoAlbumFKAndAnEInline]

        errors = MyAdmin(Album, AdminSite()).check()
        self.assertEqual(errors, []) 
开发者ID:nesdis,项目名称:djongo,代码行数:12,代码来源:tests.py

示例7: test_nonexistent_field_on_inline

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import TabularInline [as 别名]
def test_nonexistent_field_on_inline(self):
        class CityInline(admin.TabularInline):
            model = City
            readonly_fields = ['i_dont_exist']  # Missing attribute

        errors = CityInline(State, AdminSite()).check()
        expected = [
            checks.Error(
                "The value of 'readonly_fields[0]' is not a callable, an attribute "
                "of 'CityInline', or an attribute of 'admin_checks.City'.",
                obj=CityInline,
                id='admin.E035',
            )
        ]
        self.assertEqual(errors, expected) 
开发者ID:nesdis,项目名称:djongo,代码行数:17,代码来源:tests.py

示例8: test_custom_form_tabular_inline_overridden_label

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import TabularInline [as 别名]
def test_custom_form_tabular_inline_overridden_label(self):
        """
        SomeChildModelForm.__init__() overrides the label of a form field.
        That label is displayed in the TabularInline.
        """
        response = self.client.get(reverse('admin:admin_inlines_someparentmodel_add'))
        field = list(response.context['inline_admin_formset'].fields())[0]
        self.assertEqual(field['label'], 'new label')
        self.assertContains(response, '<th class="required">New label</th>', html=True) 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:tests.py

示例9: test_custom_min_num

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import TabularInline [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:nesdis,项目名称:djongo,代码行数:36,代码来源:tests.py

示例10: test_inline_change_fk_change_perm

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import TabularInline [as 别名]
def test_inline_change_fk_change_perm(self):
        permission = Permission.objects.get(codename='change_inner2', content_type=self.inner_ct)
        self.user.user_permissions.add(permission)
        response = self.client.get(self.holder_change_url)
        # Change permission on inner2s, so we can change existing but not add new
        self.assertContains(response, '<h2>Inner2s</h2>', count=2)
        # Just the one form for existing instances
        self.assertContains(
            response, '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="1" name="inner2_set-TOTAL_FORMS">',
            html=True
        )
        self.assertContains(
            response,
            '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2.id,
            html=True
        )
        # max-num 0 means we can't add new ones
        self.assertContains(
            response,
            '<input type="hidden" id="id_inner2_set-MAX_NUM_FORMS" value="0" name="inner2_set-MAX_NUM_FORMS">',
            html=True
        )
        # TabularInline
        self.assertContains(response, '<th class="required">Dummy</th>', html=True)
        self.assertContains(
            response,
            '<input type="number" name="inner2_set-2-0-dummy" value="%s" '
            'class="vIntegerField" id="id_inner2_set-2-0-dummy">' % self.inner2.dummy,
            html=True,
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:32,代码来源:tests.py

示例11: test_inline_change_fk_all_perms

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import TabularInline [as 别名]
def test_inline_change_fk_all_perms(self):
        permission = Permission.objects.get(codename='add_inner2', content_type=self.inner_ct)
        self.user.user_permissions.add(permission)
        permission = Permission.objects.get(codename='change_inner2', content_type=self.inner_ct)
        self.user.user_permissions.add(permission)
        permission = Permission.objects.get(codename='delete_inner2', content_type=self.inner_ct)
        self.user.user_permissions.add(permission)
        response = self.client.get(self.holder_change_url)
        # All perms on inner2s, so we can add/change/delete
        self.assertContains(response, '<h2>Inner2s</h2>', count=2)
        # One form for existing instance only, three for new
        self.assertContains(
            response,
            '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="4" name="inner2_set-TOTAL_FORMS">',
            html=True
        )
        self.assertContains(
            response,
            '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2.id,
            html=True
        )
        self.assertContains(response, 'id="id_inner2_set-0-DELETE"')
        # TabularInline
        self.assertContains(response, '<th class="required">Dummy</th>', html=True)
        self.assertContains(
            response,
            '<input type="number" name="inner2_set-2-0-dummy" value="%s" '
            'class="vIntegerField" id="id_inner2_set-2-0-dummy">' % self.inner2.dummy,
            html=True,
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:32,代码来源:tests.py

示例12: test_explicit_through_override

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import TabularInline [as 别名]
def test_explicit_through_override(self):
        """
        Regression test for #12209 -- If the explicitly provided through model
        is specified as a string, the admin should still be able use
        Model.m2m_field.through
        """
        class AuthorsInline(admin.TabularInline):
            model = Book.authors.through

        class BookAdmin(admin.ModelAdmin):
            inlines = [AuthorsInline]

        errors = BookAdmin(Book, AdminSite()).check()
        self.assertEqual(errors, []) 
开发者ID:nesdis,项目名称:djongo,代码行数:16,代码来源:tests.py

示例13: test_inline_change_fk_change_perm

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import TabularInline [as 别名]
def test_inline_change_fk_change_perm(self):
        permission = Permission.objects.get(codename='change_inner2', content_type=self.inner_ct)
        self.user.user_permissions.add(permission)
        response = self.client.get(self.holder_change_url)
        # Change permission on inner2s, so we can change existing but not add new
        self.assertContains(response, '<h2>Inner2s</h2>', count=2)
        # Just the one form for existing instances
        self.assertContains(
            response, '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="1" name="inner2_set-TOTAL_FORMS">',
            html=True
        )
        self.assertContains(
            response,
            '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2.id,
            html=True
        )
        # max-num 0 means we can't add new ones
        self.assertContains(
            response,
            '<input type="hidden" id="id_inner2_set-MAX_NUM_FORMS" value="0" name="inner2_set-MAX_NUM_FORMS">',
            html=True
        )
        # TabularInline
        self.assertContains(response, '<th class="column-dummy required">Dummy</th>', html=True)
        self.assertContains(
            response,
            '<input type="number" name="inner2_set-2-0-dummy" value="%s" '
            'class="vIntegerField" id="id_inner2_set-2-0-dummy">' % self.inner2.dummy,
            html=True,
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:32,代码来源:tests.py

示例14: test_inline_change_fk_all_perms

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import TabularInline [as 别名]
def test_inline_change_fk_all_perms(self):
        permission = Permission.objects.get(codename='add_inner2', content_type=self.inner_ct)
        self.user.user_permissions.add(permission)
        permission = Permission.objects.get(codename='change_inner2', content_type=self.inner_ct)
        self.user.user_permissions.add(permission)
        permission = Permission.objects.get(codename='delete_inner2', content_type=self.inner_ct)
        self.user.user_permissions.add(permission)
        response = self.client.get(self.holder_change_url)
        # All perms on inner2s, so we can add/change/delete
        self.assertContains(response, '<h2>Inner2s</h2>', count=2)
        # One form for existing instance only, three for new
        self.assertContains(
            response,
            '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="4" name="inner2_set-TOTAL_FORMS">',
            html=True
        )
        self.assertContains(
            response,
            '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2.id,
            html=True
        )
        self.assertContains(response, 'id="id_inner2_set-0-DELETE"')
        # TabularInline
        self.assertContains(response, '<th class="column-dummy required">Dummy</th>', html=True)
        self.assertContains(
            response,
            '<input type="number" name="inner2_set-2-0-dummy" value="%s" '
            'class="vIntegerField" id="id_inner2_set-2-0-dummy">' % self.inner2.dummy,
            html=True,
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:32,代码来源:tests.py


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