Python django.contrib.admin.sites.site() Examples
The following are 30
code examples of django.contrib.admin.sites.site().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.contrib.admin.sites
, or try the search function
.
Example #1
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_use_default_admin_site(self): self.assertEqual(admin.site.__class__.__name__, 'AdminSite')
Example #2
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_use_default_admin_site(self): self.assertEqual(admin.site.__class__.__name__, 'AdminSite')
Example #3
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_use_custom_admin_site(self): self.assertEqual(admin.site.__class__.__name__, 'CustomAdminSite')
Example #4
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def tearDown(self): admin.site = sites.site = self._old_site
Example #5
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_custom_site_not_an_admin_site(self): with self.assertRaisesMessage(ValueError, 'site must subclass AdminSite'): register(Person, site=Traveler)(NameAdmin)
Example #6
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_custom_site_registration(self): register(Person, site=self.custom_site)(NameAdmin) self.assertIsInstance(self.custom_site._registry[Person], admin.ModelAdmin)
Example #7
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def setUp(self): self.default_site = site self.custom_site = CustomSite()
Example #8
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_is_registered_not_registered_model(self): "Checks for unregistered models should return false." self.assertFalse(self.site.is_registered(Person))
Example #9
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_is_registered_model(self): "Checks for registered models should return true." self.site.register(Person) self.assertTrue(self.site.is_registered(Person))
Example #10
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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'])
Example #11
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #12
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_registration_with_star_star_options(self): self.site.register(Person, search_fields=['name']) self.assertEqual(self.site._registry[Person].search_fields, ['name'])
Example #13
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #14
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_registration_with_model_admin(self): self.site.register(Person, NameAdmin) self.assertIsInstance(self.site._registry[Person], NameAdmin)
Example #15
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def setUp(self): self.site = admin.AdminSite()
Example #16
Source File: __init__.py From rainmap-lite with GNU General Public License v3.0 | 5 votes |
def autodiscover(): autodiscover_modules('admin', register_to=site)
Example #17
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_use_custom_admin_site(self): self.assertEqual(admin.site.__class__.__name__, 'CustomAdminSite')
Example #18
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def tearDown(self): admin.site = sites.site = self._old_site
Example #19
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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()
Example #20
Source File: decorators.py From python2017 with MIT License | 5 votes |
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
Example #21
Source File: __init__.py From python2017 with MIT License | 5 votes |
def autodiscover(): autodiscover_modules('admin', register_to=site)
Example #22
Source File: decorators.py From openhgsenti with Apache License 2.0 | 5 votes |
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
Example #23
Source File: __init__.py From openhgsenti with Apache License 2.0 | 5 votes |
def autodiscover(): autodiscover_modules('admin', register_to=site)
Example #24
Source File: decorators.py From python with Apache License 2.0 | 5 votes |
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
Example #25
Source File: __init__.py From python with Apache License 2.0 | 5 votes |
def autodiscover(): autodiscover_modules('admin', register_to=site)
Example #26
Source File: file.py From django-leonardo with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #27
Source File: __init__.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def autodiscover(): autodiscover_modules('admin', register_to=site)
Example #28
Source File: __init__.py From bioforum with MIT License | 5 votes |
def autodiscover(): autodiscover_modules('admin', register_to=site)
Example #29
Source File: decorators.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
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
Example #30
Source File: __init__.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def autodiscover(): autodiscover_modules('admin', register_to=site)