当前位置: 首页>>代码示例>>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;未经允许,请勿转载。