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


Python sites.site方法代碼示例

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


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

示例1: autodiscover

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def autodiscover():
    autodiscover_modules('admin', register_to=site) 
開發者ID:cldrn,項目名稱:rainmap-lite,代碼行數:4,代碼來源:__init__.py

示例2: register

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def register(*models, **kwargs):
    """
    Registers the given model(s) classes and wrapped ModelAdmin class with
    admin site:

    @register(Author)
    class AuthorAdmin(admin.ModelAdmin):
        pass

    A kwarg of `site` can be passed as the admin site, otherwise the default
    admin site will be used.
    """
    from django.contrib.admin import ModelAdmin
    from django.contrib.admin.sites import site, AdminSite

    def _model_admin_wrapper(admin_class):
        admin_site = kwargs.pop('site', site)

        if not isinstance(admin_site, AdminSite):
            raise ValueError('site must subclass AdminSite')

        if not issubclass(admin_class, ModelAdmin):
            raise ValueError('Wrapped class must subclass ModelAdmin.')

        admin_site.register(models, admin_class=admin_class)

        return admin_class
    return _model_admin_wrapper 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:30,代碼來源:decorators.py

示例3: __init__

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def __init__(self, rel, queryset, to_field_name, *args, **kwargs):
        self.rel = rel
        self.queryset = queryset
        self.to_field_name = to_field_name
        self.max_value = None
        self.min_value = None
        kwargs.pop('widget', None)
        super(AdminFileFormField, self).__init__(
            queryset, widget=self.widget(rel, site), *args, **kwargs) 
開發者ID:django-leonardo,項目名稱:django-leonardo,代碼行數:11,代碼來源:file.py

示例4: register

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def register(*models, **kwargs):
    """
    Registers the given model(s) classes and wrapped ModelAdmin class with
    admin site:

    @register(Author)
    class AuthorAdmin(admin.ModelAdmin):
        pass

    A kwarg of `site` can be passed as the admin site, otherwise the default
    admin site will be used.
    """
    from django.contrib.admin import ModelAdmin
    from django.contrib.admin.sites import site, AdminSite

    def _model_admin_wrapper(admin_class):
        if not models:
            raise ValueError('At least one model must be passed to register.')

        admin_site = kwargs.pop('site', site)

        if not isinstance(admin_site, AdminSite):
            raise ValueError('site must subclass AdminSite')

        if not issubclass(admin_class, ModelAdmin):
            raise ValueError('Wrapped class must subclass ModelAdmin.')

        admin_site.register(models, admin_class=admin_class)

        return admin_class
    return _model_admin_wrapper 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:33,代碼來源:decorators.py

示例5: setUp

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def setUp(self):
        # Reset admin.site since it may have already been instantiated by
        # another test app.
        self._old_site = admin.site
        admin.site = sites.site = sites.DefaultAdminSite() 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:tests.py

示例6: tearDown

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def tearDown(self):
        admin.site = sites.site = self._old_site 
開發者ID:nesdis,項目名稱:djongo,代碼行數:4,代碼來源:tests.py

示例7: test_use_custom_admin_site

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def test_use_custom_admin_site(self):
        self.assertEqual(admin.site.__class__.__name__, 'CustomAdminSite') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:4,代碼來源:tests.py

示例8: test_use_default_admin_site

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def test_use_default_admin_site(self):
        self.assertEqual(admin.site.__class__.__name__, 'AdminSite') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:4,代碼來源:tests.py

示例9: setUp

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def setUp(self):
        self.site = admin.AdminSite() 
開發者ID:nesdis,項目名稱:djongo,代碼行數:4,代碼來源:tests.py

示例10: test_registration_with_model_admin

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def test_registration_with_model_admin(self):
        self.site.register(Person, NameAdmin)
        self.assertIsInstance(self.site._registry[Person], NameAdmin) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:5,代碼來源:tests.py

示例11: test_prevent_double_registration

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def test_prevent_double_registration(self):
        self.site.register(Person)
        msg = 'The model Person is already registered'
        with self.assertRaisesMessage(admin.sites.AlreadyRegistered, msg):
            self.site.register(Person) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:tests.py

示例12: test_registration_with_star_star_options

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def test_registration_with_star_star_options(self):
        self.site.register(Person, search_fields=['name'])
        self.assertEqual(self.site._registry[Person].search_fields, ['name']) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:5,代碼來源:tests.py

示例13: test_star_star_overrides

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def test_star_star_overrides(self):
        self.site.register(Person, NameAdmin, search_fields=["name"], list_display=['__str__'])
        self.assertEqual(self.site._registry[Person].search_fields, ['name'])
        self.assertEqual(self.site._registry[Person].list_display, ['__str__'])
        self.assertTrue(self.site._registry[Person].save_on_top) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:tests.py

示例14: test_iterable_registration

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def test_iterable_registration(self):
        self.site.register([Person, Place], search_fields=['name'])
        self.assertIsInstance(self.site._registry[Person], admin.ModelAdmin)
        self.assertEqual(self.site._registry[Person].search_fields, ['name'])
        self.assertIsInstance(self.site._registry[Place], admin.ModelAdmin)
        self.assertEqual(self.site._registry[Place].search_fields, ['name']) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:8,代碼來源:tests.py

示例15: test_is_registered_model

# 需要導入模塊: from django.contrib.admin import sites [as 別名]
# 或者: from django.contrib.admin.sites import site [as 別名]
def test_is_registered_model(self):
        "Checks for registered models should return true."
        self.site.register(Person)
        self.assertTrue(self.site.is_registered(Person)) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:tests.py


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