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


Python admin.ModelAdmin方法代碼示例

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


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

示例1: get_excluded_fields

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [as 別名]
def get_excluded_fields(self):
        """
        Check if we have no excluded fields defined as we never want to
        show those (to any user)
        """
        if self.exclude is None:
            exclude = []
        else:
            exclude = list(self.exclude)

        # logic taken from: django.contrib.admin.options.ModelAdmin#get_form
        if self.exclude is None and hasattr(
                self.form, '_meta') and self.form._meta.exclude:
            # Take the custom ModelForm's Meta.exclude into account only
            # if the ModelAdmin doesn't define its own.
            exclude.extend(self.form._meta.exclude)

        return exclude 
開發者ID:ctxis,項目名稱:django-admin-view-permission,代碼行數:20,代碼來源:admin.py

示例2: get_queryset

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [as 別名]
def get_queryset(self, request):
        self.last_request = request
        # qs = admin.ModelAdmin.get_queryset(self, request)
        qs = TermUsage.objects.all()
        if 'q' in request.GET:
            # searching by count?
            request.GET = request.GET.copy()
            query_text = request.GET.pop('q')
            query_text = query_text[0] if query_text else ''
            if query_text:
                queries = Q(term__term__icontains=query_text) | \
                          Q(document__name__icontains=query_text) | \
                          Q(document__project__name__icontains=query_text)
                if query_text.isdigit():
                    queries |= (Q(count__gt=int(query_text) - 1))
                qs = qs.filter(queries)
        qs = qs.only('id', 'text_unit_id', 'count', 'term')
        qs = self.filter_count_predicate(qs)
        return qs 
開發者ID:LexPredict,項目名稱:lexpredict-contraxsuite,代碼行數:21,代碼來源:admin.py

示例3: csr_details_view

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [as 別名]
def csr_details_view(self, request):
        """Returns details of a CSR request."""

        if not request.user.is_staff or not self.has_change_permission(request):
            # NOTE: is_staff is already assured by ModelAdmin, but just to be sure
            raise PermissionDenied

        try:
            csr = x509.load_pem_x509_csr(force_bytes(request.POST['csr']), default_backend())
        except Exception as e:
            return HttpResponseBadRequest(json.dumps({
                'message': str(e),
            }), content_type='application/json')

        subject = {OID_NAME_MAPPINGS[s.oid]: s.value for s in csr.subject}
        return HttpResponse(json.dumps({
            'subject': subject,
        }), content_type='application/json') 
開發者ID:mathiasertl,項目名稱:django-ca,代碼行數:20,代碼來源:admin.py

示例4: attempt_register

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [as 別名]
def attempt_register(self, Model, ModelAdmin):
        try:
            admin.site.unregister(Model)
        except admin.sites.NotRegistered:
            pass
        try:
            admin.site.register(Model, ModelAdmin)
        except admin.sites.AlreadyRegistered:
            logger.warning("WARNING! %s admin already exists." % (
                str(Model)
            ))

        # If we don't do this, our module will show up in admin but
        # it will show up as an unclickable thing with on add/change
        importlib.reload(import_module(settings.ROOT_URLCONF))
        clear_url_caches() 
開發者ID:propublica,項目名稱:django-collaborative,代碼行數:18,代碼來源:admin.py

示例5: change_view

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [as 別名]
def change_view(self, request, object_id, form_url='', extra_context=None):
        """
        Overriden to show all plugin's fields in the view plugin page.
        """
        self.readonly_fields = [fl for fl in plugin_readonly_fields]
        self.readonly_fields.append('get_registered_compute_resources')
        self.fieldsets = [
            ('Compute resources', {'fields': ['compute_resources',
                                              'get_registered_compute_resources']}),
            ('Plugin properties', {'fields': plugin_readonly_fields}),
        ]
        return admin.ModelAdmin.change_view(self, request, object_id, form_url,
                                            extra_context)

    # def save_model(self, request, obj, form, change):
    #     """
    #     Overriden to set the modification date..
    #     """
    #     if change:
    #         obj.modification_date = timezone.now()
    #     super().save_model(request, obj, form, change) 
開發者ID:FNNDSC,項目名稱:ChRIS_ultron_backEnd,代碼行數:23,代碼來源:admin.py

示例6: test_allows_checks_relying_on_other_modeladmins

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [as 別名]
def test_allows_checks_relying_on_other_modeladmins(self):
        class MyBookAdmin(admin.ModelAdmin):
            def check(self, **kwargs):
                errors = super().check(**kwargs)
                author_admin = self.admin_site._registry.get(Author)
                if author_admin is None:
                    errors.append('AuthorAdmin missing!')
                return errors

        class MyAuthorAdmin(admin.ModelAdmin):
            pass

        admin.site.register(Book, MyBookAdmin)
        admin.site.register(Author, MyAuthorAdmin)
        try:
            self.assertEqual(admin.site.check(None), [])
        finally:
            admin.site.unregister(Book)
            admin.site.unregister(Author) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:21,代碼來源:tests.py

示例7: test_fieldsets_fields_non_tuple

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [as 別名]
def test_fieldsets_fields_non_tuple(self):
        """
        The first fieldset's fields must be a list/tuple.
        """
        class NotATupleAdmin(admin.ModelAdmin):
            list_display = ["pk", "title"]
            list_editable = ["title"]
            fieldsets = [
                (None, {
                    "fields": "title"  # not a tuple
                }),
            ]

        errors = NotATupleAdmin(Song, AdminSite()).check()
        expected = [
            checks.Error(
                "The value of 'fieldsets[0][1]['fields']' must be a list or tuple.",
                obj=NotATupleAdmin,
                id='admin.E008',
            )
        ]
        self.assertEqual(errors, expected) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:24,代碼來源:tests.py

示例8: test_nonfirst_fieldset

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [as 別名]
def test_nonfirst_fieldset(self):
        """
        The second fieldset's fields must be a list/tuple.
        """
        class NotATupleAdmin(admin.ModelAdmin):
            fieldsets = [
                (None, {
                    "fields": ("title",)
                }),
                ('foo', {
                    "fields": "author"  # not a tuple
                }),
            ]

        errors = NotATupleAdmin(Song, AdminSite()).check()
        expected = [
            checks.Error(
                "The value of 'fieldsets[1][1]['fields']' must be a list or tuple.",
                obj=NotATupleAdmin,
                id='admin.E008',
            )
        ]
        self.assertEqual(errors, expected) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:25,代碼來源:tests.py

示例9: test_exclude_values

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [as 別名]
def test_exclude_values(self):
        """
        Tests for basic system checks of 'exclude' option values (#12689)
        """
        class ExcludedFields1(admin.ModelAdmin):
            exclude = 'foo'

        errors = ExcludedFields1(Book, AdminSite()).check()
        expected = [
            checks.Error(
                "The value of 'exclude' must be a list or tuple.",
                obj=ExcludedFields1,
                id='admin.E014',
            )
        ]
        self.assertEqual(errors, expected) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:tests.py

示例10: test_exclude_in_inline

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [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

示例11: test_exclude_inline_model_admin

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [as 別名]
def test_exclude_inline_model_admin(self):
        """
        Regression test for #9932 - exclude in InlineModelAdmin should not
        contain the ForeignKey field used in ModelAdmin.model
        """
        class SongInline(admin.StackedInline):
            model = Song
            exclude = ['album']

        class AlbumAdmin(admin.ModelAdmin):
            model = Album
            inlines = [SongInline]

        errors = AlbumAdmin(Album, AdminSite()).check()
        expected = [
            checks.Error(
                "Cannot exclude the field 'album', because it is the foreign key "
                "to the parent model 'admin_checks.Album'.",
                obj=SongInline,
                id='admin.E201',
            )
        ]
        self.assertEqual(errors, expected) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:25,代碼來源:tests.py

示例12: test_generic_inline_model_admin_non_generic_model

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [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

示例13: test_generic_inline_model_admin_bad_ct_field

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [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

示例14: test_generic_inline_model_admin_non_gfk_ct_field

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [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

示例15: test_generic_inline_model_admin_non_gfk_fk_field

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import ModelAdmin [as 別名]
def test_generic_inline_model_admin_non_gfk_fk_field(self):
        """
        A GenericInlineModelAdmin raises problems if the ct_fk_field points to
        a field that isn't part of a GenericForeignKey.
        """
        class InfluenceInline(GenericStackedInline):
            model = Influence
            ct_fk_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 'content_type' and object ID field 'name'.",
                obj=InfluenceInline,
                id='admin.E304',
            )
        ]
        self.assertEqual(errors, expected) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:24,代碼來源:tests.py


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