本文整理汇总了Python中django.contrib.admin.options.ModelAdmin方法的典型用法代码示例。如果您正苦于以下问题:Python options.ModelAdmin方法的具体用法?Python options.ModelAdmin怎么用?Python options.ModelAdmin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.options
的用法示例。
在下文中一共展示了options.ModelAdmin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_inline_instances
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def get_inline_instances(self, request, obj=None):
"""
Overwrites BaseModelAdmin fieldsets to add fieldsets passed by the
tabs.
If the tabs attribute is not set, use the default ModelAdmin method.
"""
if self.tabs is not None:
self.inlines = ()
tabs_inlines = self.get_formatted_tabs(request, obj)['inlines']
self.inlines = self.add_tabbed_item(tabs_inlines, self.inlines)
try:
# django >=1.7
return super(TabbedModelAdmin, self)\
.get_inline_instances(request, obj)
except TypeError:
return super(TabbedModelAdmin, self).get_inline_instances(request)
示例2: test_list_display_link_checked_for_list_tuple_if_get_list_display_overridden
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def test_list_display_link_checked_for_list_tuple_if_get_list_display_overridden(self):
"""
list_display_links is checked for list/tuple/None even if
get_list_display() is overridden.
"""
class TestModelAdmin(ModelAdmin):
list_display_links = 'non-list/tuple'
def get_list_display(self, request):
pass
self.assertIsInvalid(
TestModelAdmin, ValidationTestModel,
"The value of 'list_display_links' must be a list, a tuple, or None.",
'admin.E110'
)
示例3: test_not_filter_again_again
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def test_not_filter_again_again(self):
class AwesomeFilter(SimpleListFilter):
def get_title(self):
return 'awesomeness'
def get_choices(self, request):
return (('bit', 'A bit awesome'), ('very', 'Very awesome'))
def get_queryset(self, cl, qs):
return qs
class TestModelAdmin(ModelAdmin):
list_filter = (('is_active', AwesomeFilter),)
self.assertIsInvalid(
TestModelAdmin, ValidationTestModel,
"The value of 'list_filter[0][1]' must inherit from 'FieldListFilter'.",
'admin.E115'
)
示例4: test_not_iterable
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def test_not_iterable(self):
class TestModelAdmin(ModelAdmin):
ordering = 10
self.assertIsInvalid(
TestModelAdmin, ValidationTestModel,
"The value of 'ordering' must be a list or tuple.",
'admin.E031'
)
class TestModelAdmin(ModelAdmin):
ordering = ('non_existent_field',)
self.assertIsInvalid(
TestModelAdmin, ValidationTestModel,
"The value of 'ordering[0]' refers to 'non_existent_field', "
"which is not an attribute of 'modeladmin.ValidationTestModel'.",
'admin.E033'
)
示例5: get_fieldsets
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def get_fieldsets(self, request, obj=None):
"""
Overwrites BaseModelAdmin fieldsets to add fieldsets passed by the
tabs.
If the tabs attribute is not set, use the default ModelAdmin method.
"""
tabs_fieldsets = self.get_formatted_tabs(request, obj)['fieldsets']
if self.tabs is not None:
self.fieldsets = ()
self.fieldsets = self.add_tabbed_item(tabs_fieldsets, self.fieldsets)
return super(TabbedModelAdmin, self).get_fieldsets(request, obj)
示例6: test_fieldset
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def test_fieldset(self):
ma = ModelAdmin(Programme, self.site)
self.assertEqual(
ma.get_fields(None),
['name', 'synopsis', 'photo', 'language', 'current_season', 'category', 'slug', '_runtime', 'start_date', 'end_date'])
示例7: test_vatin_field_admin
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def test_vatin_field_admin(self):
"""Admin form is generated."""
ma = ModelAdmin(VIESModel, self.site)
try:
ma.get_form(request)
except Exception as e:
self.fail(e.message)
示例8: test_missing_field
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def test_missing_field(self):
class TestModelAdmin(ModelAdmin):
raw_id_fields = ('non_existent_field',)
self.assertIsInvalid(
TestModelAdmin, ValidationTestModel,
"The value of 'raw_id_fields[0]' refers to 'non_existent_field', "
"which is not an attribute of 'modeladmin.ValidationTestModel'.",
'admin.E002'
)
示例9: test_invalid_field_type
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def test_invalid_field_type(self):
class TestModelAdmin(ModelAdmin):
raw_id_fields = ('name',)
self.assertIsInvalid(
TestModelAdmin, ValidationTestModel,
"The value of 'raw_id_fields[0]' must be a foreign key or a "
"many-to-many field.",
'admin.E003'
)
示例10: test_valid_case
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def test_valid_case(self):
class TestModelAdmin(ModelAdmin):
raw_id_fields = ('users',)
self.assertIsValid(TestModelAdmin, ValidationTestModel)
示例11: test_non_iterable_item
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def test_non_iterable_item(self):
class TestModelAdmin(ModelAdmin):
fieldsets = ({},)
self.assertIsInvalid(
TestModelAdmin, ValidationTestModel,
"The value of 'fieldsets[0]' must be a list or tuple.",
'admin.E008'
)
示例12: test_item_not_a_pair
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def test_item_not_a_pair(self):
class TestModelAdmin(ModelAdmin):
fieldsets = ((),)
self.assertIsInvalid(
TestModelAdmin, ValidationTestModel,
"The value of 'fieldsets[0]' must be of length 2.",
'admin.E009'
)
示例13: test_second_element_of_item_not_a_dict
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def test_second_element_of_item_not_a_dict(self):
class TestModelAdmin(ModelAdmin):
fieldsets = (('General', ()),)
self.assertIsInvalid(
TestModelAdmin, ValidationTestModel,
"The value of 'fieldsets[0][1]' must be a dictionary.",
'admin.E010'
)
示例14: test_missing_fields_key
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def test_missing_fields_key(self):
class TestModelAdmin(ModelAdmin):
fieldsets = (('General', {}),)
self.assertIsInvalid(
TestModelAdmin, ValidationTestModel,
"The value of 'fieldsets[0][1]' must contain the key 'fields'.",
'admin.E011'
)
class TestModelAdmin(ModelAdmin):
fieldsets = (('General', {'fields': ('name',)}),)
self.assertIsValid(TestModelAdmin, ValidationTestModel)
示例15: test_specified_both_fields_and_fieldsets
# 需要导入模块: from django.contrib.admin import options [as 别名]
# 或者: from django.contrib.admin.options import ModelAdmin [as 别名]
def test_specified_both_fields_and_fieldsets(self):
class TestModelAdmin(ModelAdmin):
fieldsets = (('General', {'fields': ('name',)}),)
fields = ['name']
self.assertIsInvalid(
TestModelAdmin, ValidationTestModel,
"Both 'fieldsets' and 'fields' are specified.",
'admin.E005'
)