1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #25688 -- Made admin.register() disallow an empty list of models.

This commit is contained in:
Hasan 2015-11-06 09:51:29 +03:30 committed by Tim Graham
parent c550beb0cc
commit 8c553e7d3f
2 changed files with 7 additions and 0 deletions

View File

@ -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):

View File

@ -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)