本文整理汇总了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)
示例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
示例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)
示例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
示例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()
示例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
示例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')
示例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')
示例9: setUp
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import site [as 别名]
def setUp(self):
self.site = admin.AdminSite()
示例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)
示例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)
示例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'])
示例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)
示例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'])
示例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))