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


Python admin.autodiscover方法代碼示例

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


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

示例1: handle_noargs

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import autodiscover [as 別名]
def handle_noargs(self, *args, **options):
        from bananas import admin
        from django.contrib import admin as django_admin
        from django.contrib.contenttypes.models import ContentType

        django_admin.autodiscover()

        for model, _ in admin.site._registry.items():
            if issubclass(getattr(model, "View", object), admin.AdminView):
                meta = model._meta

                ct, created = ContentType.objects.get_or_create(
                    app_label=meta.app_label, model=meta.object_name.lower()
                )

                if created:
                    print("Found new admin view: {} [{}]".format(ct.name, ct.app_label))

                for codename, name in model._meta.permissions:
                    p, created = Permission.objects.update_or_create(
                        codename=codename, content_type=ct, defaults=dict(name=name)
                    )
                    if created:
                        print("Created permission: {}".format(name)) 
開發者ID:5monkeys,項目名稱:django-bananas,代碼行數:26,代碼來源:syncpermissions.py

示例2: test_check_custom_user_model_custom_admin

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import autodiscover [as 別名]
def test_check_custom_user_model_custom_admin(self):
            class CustomAdminSite(admin.AdminSite):
                pass

            _default_site = admin.site
            admin.site = CustomAdminSite()
            admin.autodiscover()

            admin.site.register(get_user_model(), HijackUserAdmin)

            warnings = checks.check_custom_user_model(HijackAdminConfig)
            self.assertFalse(warnings)

            admin.site.unregister(get_user_model())
            admin.site = _default_site 
開發者ID:arteria,項目名稱:django-hijack-admin,代碼行數:17,代碼來源:test_checks.py

示例3: test_double_call_autodiscover

# 需要導入模塊: from django.contrib import admin [as 別名]
# 或者: from django.contrib.admin import autodiscover [as 別名]
def test_double_call_autodiscover(self):
        # The first time autodiscover is called, we should get our real error.
        with self.assertRaises(Exception) as cm:
            admin.autodiscover()
        self.assertEqual(str(cm.exception), "Bad admin module")

        # Calling autodiscover again should raise the very same error it did
        # the first time, not an AlreadyRegistered error.
        with self.assertRaises(Exception) as cm:
            admin.autodiscover()
        self.assertEqual(str(cm.exception), "Bad admin module") 
開發者ID:nesdis,項目名稱:djongo,代碼行數:13,代碼來源:tests.py


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