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


Python options.ModelAdmin方法代碼示例

本文整理匯總了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) 
開發者ID:omji,項目名稱:django-tabbed-admin,代碼行數:19,代碼來源:admin.py

示例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'
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:test_checks.py

示例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'
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:21,代碼來源:test_checks.py

示例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'
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:21,代碼來源:test_checks.py

示例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) 
開發者ID:omji,項目名稱:django-tabbed-admin,代碼行數:13,代碼來源:admin.py

示例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']) 
開發者ID:iago1460,項目名稱:django-radio,代碼行數:7,代碼來源:test_models.py

示例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) 
開發者ID:codingjoe,項目名稱:django-vies,代碼行數:10,代碼來源:test_widgets.py

示例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'
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:12,代碼來源:test_checks.py

示例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'
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:12,代碼來源:test_checks.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:test_checks.py

示例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'
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:11,代碼來源:test_checks.py

示例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'
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:11,代碼來源:test_checks.py

示例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'
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:11,代碼來源:test_checks.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:16,代碼來源:test_checks.py

示例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'
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:12,代碼來源:test_checks.py


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