當前位置: 首頁>>代碼示例>>Python>>正文


Python admin.GenericStackedInline方法代碼示例

本文整理匯總了Python中django.contrib.contenttypes.admin.GenericStackedInline方法的典型用法代碼示例。如果您正苦於以下問題:Python admin.GenericStackedInline方法的具體用法?Python admin.GenericStackedInline怎麽用?Python admin.GenericStackedInline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.contrib.contenttypes.admin的用法示例。


在下文中一共展示了admin.GenericStackedInline方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_generic_inline_model_admin_non_generic_model

# 需要導入模塊: from django.contrib.contenttypes import admin [as 別名]
# 或者: from django.contrib.contenttypes.admin import GenericStackedInline [as 別名]
def test_generic_inline_model_admin_non_generic_model(self):
        """
        A model without a GenericForeignKey raises problems if it's included
        in a GenericInlineModelAdmin definition.
        """
        class BookInline(GenericStackedInline):
            model = Book

        class SongAdmin(admin.ModelAdmin):
            inlines = [BookInline]

        errors = SongAdmin(Song, AdminSite()).check()
        expected = [
            checks.Error(
                "'admin_checks.Book' has no GenericForeignKey.",
                obj=BookInline,
                id='admin.E301',
            )
        ]
        self.assertEqual(errors, expected) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:22,代碼來源:tests.py

示例2: test_generic_inline_model_admin_bad_ct_field

# 需要導入模塊: from django.contrib.contenttypes import admin [as 別名]
# 或者: from django.contrib.contenttypes.admin import GenericStackedInline [as 別名]
def test_generic_inline_model_admin_bad_ct_field(self):
        """
        A GenericInlineModelAdmin errors if the ct_field points to a
        nonexistent field.
        """
        class InfluenceInline(GenericStackedInline):
            model = Influence
            ct_field = 'nonexistent'

        class SongAdmin(admin.ModelAdmin):
            inlines = [InfluenceInline]

        errors = SongAdmin(Song, AdminSite()).check()
        expected = [
            checks.Error(
                "'ct_field' references 'nonexistent', which is not a field on 'admin_checks.Influence'.",
                obj=InfluenceInline,
                id='admin.E302',
            )
        ]
        self.assertEqual(errors, expected) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:23,代碼來源:tests.py

示例3: test_generic_inline_model_admin_bad_fk_field

# 需要導入模塊: from django.contrib.contenttypes import admin [as 別名]
# 或者: from django.contrib.contenttypes.admin import GenericStackedInline [as 別名]
def test_generic_inline_model_admin_bad_fk_field(self):
        """
        A GenericInlineModelAdmin errors if the ct_fk_field points to a
        nonexistent field.
        """
        class InfluenceInline(GenericStackedInline):
            model = Influence
            ct_fk_field = 'nonexistent'

        class SongAdmin(admin.ModelAdmin):
            inlines = [InfluenceInline]

        errors = SongAdmin(Song, AdminSite()).check()
        expected = [
            checks.Error(
                "'ct_fk_field' references 'nonexistent', which is not a field on 'admin_checks.Influence'.",
                obj=InfluenceInline,
                id='admin.E303',
            )
        ]
        self.assertEqual(errors, expected) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:23,代碼來源:tests.py

示例4: test_generic_inline_model_admin_non_gfk_ct_field

# 需要導入模塊: from django.contrib.contenttypes import admin [as 別名]
# 或者: from django.contrib.contenttypes.admin import GenericStackedInline [as 別名]
def test_generic_inline_model_admin_non_gfk_ct_field(self):
        """
        A GenericInlineModelAdmin raises problems if the ct_field points to a
        field that isn't part of a GenericForeignKey.
        """
        class InfluenceInline(GenericStackedInline):
            model = Influence
            ct_field = 'name'

        class SongAdmin(admin.ModelAdmin):
            inlines = [InfluenceInline]

        errors = SongAdmin(Song, AdminSite()).check()
        expected = [
            checks.Error(
                "'admin_checks.Influence' has no GenericForeignKey using "
                "content type field 'name' and object ID field 'object_id'.",
                obj=InfluenceInline,
                id='admin.E304',
            )
        ]
        self.assertEqual(errors, expected) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:24,代碼來源:tests.py

示例5: get_inline

# 需要導入模塊: from django.contrib.contenttypes import admin [as 別名]
# 或者: from django.contrib.contenttypes.admin import GenericStackedInline [as 別名]
def get_inline(metadata_class):
    attrs = {
        'max_num': 1,
        'extra': 1,
        'model': metadata_class._meta.get_model('modelinstance'),
        'ct_field': "_content_type",
        'ct_fk_field': "_object_id",
        'formset': MetadataFormset,
    }
    return type('MetadataInline', (GenericStackedInline,), attrs) 
開發者ID:whyflyru,項目名稱:django-seo,代碼行數:12,代碼來源:admin.py

示例6: get_inline

# 需要導入模塊: from django.contrib.contenttypes import admin [as 別名]
# 或者: from django.contrib.contenttypes.admin import GenericStackedInline [as 別名]
def get_inline(metadata_class):
    attrs = {
        'max_num': 1,
        'extra': 1,
        'model': metadata_class._meta.get_model('modelinstance'),
        'ct_field': "_content_type",
        'ct_fk_field': "_object_id",
        'formset': MetadataFormset,
    }
    return type(str('MetadataInline'), (GenericStackedInline,), attrs) 
開發者ID:romansalin,項目名稱:django-seo2,代碼行數:12,代碼來源:admin.py

示例7: test_valid_generic_inline_model_admin

# 需要導入模塊: from django.contrib.contenttypes import admin [as 別名]
# 或者: from django.contrib.contenttypes.admin import GenericStackedInline [as 別名]
def test_valid_generic_inline_model_admin(self):
        """
        Regression test for #22034 - check that generic inlines don't look for
        normal ForeignKey relations.
        """
        class InfluenceInline(GenericStackedInline):
            model = Influence

        class SongAdmin(admin.ModelAdmin):
            inlines = [InfluenceInline]

        errors = SongAdmin(Song, AdminSite()).check()
        self.assertEqual(errors, []) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:15,代碼來源:tests.py


注:本文中的django.contrib.contenttypes.admin.GenericStackedInline方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。