Ticket #25688: empty_list_fails_to_register.diff

File empty_list_fails_to_register.diff, 1.5 KB (added by Aaron Elliot Ross, 8 years ago)

Adds a test and applies requested fixes to comments.

  • django/contrib/admin/decorators.py

    diff --git a/django/contrib/admin/decorators.py b/django/contrib/admin/decorators.py
    index 5862bb5..27f0e74 100644
    a b def register(*models, **kwargs): 
    1010    A kwarg of `site` can be passed as the admin site, otherwise the default
    1111    admin site will be used.
     13    At least one model must be passed to register.
    1214    """
    1315    from django.contrib.admin import ModelAdmin
    1416    from django.contrib.admin.sites import site, AdminSite
    def register(*models, **kwargs): 
    2224        if not issubclass(admin_class, ModelAdmin):
    2325            raise ValueError('Wrapped class must subclass ModelAdmin.')
     27        if not models:
     28            raise ValueError('At least one model must be passed to register.')
    2530        admin_site.register(models, admin_class=admin_class)
    2732        return admin_class
  • tests/admin_registration/tests.py

    diff --git a/tests/admin_registration/tests.py b/tests/admin_registration/tests.py
    index 7471c52..9e0b7fb 100644
    a b class TestRegistrationDecorator(SimpleTestCase): 
    133133    def test_custom_site_not_an_admin_site(self):
    134134        self.assertRaisesMessage(ValueError, 'site must subclass AdminSite',
    135135            register(Person, site=Traveler), NameAdmin)
     137    def test_empty_list_registration_fails(self):
     138        self.assertRaisesMessage(ValueError, 'At least one model must be passed to register.',
     139            register(), NameAdmin)
Back to Top