diff --git a/django/contrib/admin/decorators.py b/django/contrib/admin/decorators.py index 5862bb5536f..8b30139ea3d 100644 --- a/django/contrib/admin/decorators.py +++ b/django/contrib/admin/decorators.py @@ -14,6 +14,9 @@ def register(*models, **kwargs): 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): diff --git a/tests/admin_registration/tests.py b/tests/admin_registration/tests.py index 7471c521d6c..202fed86e3e 100644 --- a/tests/admin_registration/tests.py +++ b/tests/admin_registration/tests.py @@ -133,3 +133,7 @@ class TestRegistrationDecorator(SimpleTestCase): def test_custom_site_not_an_admin_site(self): self.assertRaisesMessage(ValueError, 'site must subclass AdminSite', register(Person, site=Traveler), NameAdmin) + + def test_empty_models_list_registration_fails(self): + with self.assertRaisesMessage(ValueError, 'At least one model must be passed to register.'): + register()(NameAdmin)