本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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, [])