diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
index c1f6970..870ab04 100644
a
|
b
|
class AdminSite(object):
|
61 | 61 | they'll be applied as options to the admin class. |
62 | 62 | |
63 | 63 | If a model is already registered, this will raise AlreadyRegistered. |
| 64 | |
| 65 | If a model is abstract, this will raise ImproperlyConfigured. |
64 | 66 | """ |
65 | 67 | if not admin_class: |
66 | 68 | admin_class = ModelAdmin |
… |
… |
class AdminSite(object):
|
74 | 76 | if isinstance(model_or_iterable, ModelBase): |
75 | 77 | model_or_iterable = [model_or_iterable] |
76 | 78 | for model in model_or_iterable: |
| 79 | if model._meta.abstract: |
| 80 | raise ImproperlyConfigured('The model %s is abstract and ' |
| 81 | 'therefore cannot be registered' % model.__name__) |
| 82 | |
77 | 83 | if model in self._registry: |
78 | 84 | raise AlreadyRegistered('The model %s is already registered' % model.__name__) |
79 | 85 | |
diff --git a/tests/regressiontests/admin_registration/models.py b/tests/regressiontests/admin_registration/models.py
index 4a2d4e9..129530d 100644
a
|
b
|
from django.db import models
|
7 | 7 | class Person(models.Model): |
8 | 8 | name = models.CharField(max_length=200) |
9 | 9 | |
10 | | class Place(models.Model): |
| 10 | class Location(models.Model): |
| 11 | class Meta: |
| 12 | abstract = True |
| 13 | |
| 14 | class Place(Location): |
11 | 15 | name = models.CharField(max_length=200) |
diff --git a/tests/regressiontests/admin_registration/tests.py b/tests/regressiontests/admin_registration/tests.py
index e2a5d7e..92e9d8a 100644
a
|
b
|
|
1 | 1 | from django.test import TestCase |
2 | | |
| 2 | from django.core.exceptions import ImproperlyConfigured |
3 | 3 | from django.contrib import admin |
4 | 4 | |
5 | | from models import Person, Place |
| 5 | from models import Person, Place, Location |
6 | 6 | |
7 | 7 | class NameAdmin(admin.ModelAdmin): |
8 | 8 | list_display = ['name'] |
… |
… |
class TestRegistration(TestCase):
|
52 | 52 | isinstance(self.site._registry[Place], admin.options.ModelAdmin) |
53 | 53 | ) |
54 | 54 | self.assertEqual(self.site._registry[Place].search_fields, ['name']) |
| 55 | |
| 56 | def test_abstract_model(self): |
| 57 | """ |
| 58 | Exception is raised when trying to register an abstract model. |
| 59 | Refs #12004. |
| 60 | """ |
| 61 | self.assertRaises(ImproperlyConfigured, self.site.register, Location) |