diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
index d0d6473..f7de7df 100644
a
|
b
|
class AdminSite(object):
|
74 | 74 | if isinstance(model_or_iterable, ModelBase): |
75 | 75 | model_or_iterable = [model_or_iterable] |
76 | 76 | for model in model_or_iterable: |
| 77 | if model._meta.abstract: |
| 78 | raise ImproperlyConfigured('Unable to register abstract model %s' % model.__name__) |
| 79 | |
77 | 80 | if model in self._registry: |
78 | 81 | raise AlreadyRegistered('The model %s is already registered' % model.__name__) |
79 | 82 | |
diff --git a/tests/regressiontests/admin_views/abstractadmin.py b/tests/regressiontests/admin_views/abstractadmin.py
new file mode 100644
index 0000000..71d372b
-
|
+
|
|
| 1 | """ |
| 2 | see tests.AbstractAdminTest |
| 3 | """ |
| 4 | from django.contrib import admin |
| 5 | |
| 6 | import models |
| 7 | |
| 8 | site = admin.AdminSite(name="abstractadmin") |
| 9 | |
| 10 | site.register(models.Pizza) |
| 11 | |
| 12 | def do_register(): |
| 13 | # This method should raise an ImproperlyConfigured exception |
| 14 | site.register(models.AbstractPizza) |
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
index b25a9b9..946b6a7 100644
a
|
b
|
class CyclicTwo(models.Model):
|
573 | 573 | class Topping(models.Model): |
574 | 574 | name = models.CharField(max_length=20) |
575 | 575 | |
576 | | class Pizza(models.Model): |
| 576 | class AbstractPizza(models.Model): |
577 | 577 | name = models.CharField(max_length=20) |
| 578 | |
| 579 | class Meta: |
| 580 | abstract = True |
| 581 | |
| 582 | class Pizza(AbstractPizza): |
578 | 583 | toppings = models.ManyToManyField('Topping') |
579 | 584 | |
580 | 585 | class PizzaAdmin(admin.ModelAdmin): |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 725369a..15845b8 100644
a
|
b
|
|
3 | 3 | import re |
4 | 4 | import datetime |
5 | 5 | from django.conf import settings |
| 6 | from django.core.exceptions import ImproperlyConfigured |
6 | 7 | from django.core.files import temp as tempfile |
7 | 8 | from django.contrib.auth import admin # Register auth models with the admin. |
8 | 9 | from django.contrib.auth.models import User, Permission, UNUSABLE_PASSWORD |
… |
… |
from models import Article, BarAccount, CustomArticle, EmptyModel, \
|
24 | 25 | FooAccount, Gallery, ModelWithStringPrimaryKey, \ |
25 | 26 | Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \ |
26 | 27 | Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \ |
27 | | Category, Post, Plot, FunkyTag |
| 28 | Category, Post, Plot, FunkyTag, AbstractPizza |
28 | 29 | |
29 | 30 | |
30 | 31 | class AdminViewBasicTest(TestCase): |
… |
… |
class CustomModelAdminTest(AdminViewBasicTest):
|
360 | 361 | response = self.client.get('/test_admin/%s/my_view/' % self.urlbit) |
361 | 362 | self.assert_(response.content == "Django is a magical pony!", response.content) |
362 | 363 | |
| 364 | class AbstractAdminTest(TestCase): |
| 365 | fixtures = ['admin-views-users.xml'] |
| 366 | |
| 367 | urlbit = "abstractadmin" |
| 368 | |
| 369 | def setUp(self): |
| 370 | self.old_language_code = settings.LANGUAGE_CODE |
| 371 | self.client.login(username='super', password='secret') |
| 372 | |
| 373 | def tearDown(self): |
| 374 | settings.LANGUAGE_CODE = self.old_language_code |
| 375 | self.client.logout() |
| 376 | |
| 377 | def test_abstract_register(self): |
| 378 | """ |
| 379 | Regression test for #12004: |
| 380 | Exception is raised when trying to register an abstract model |
| 381 | """ |
| 382 | |
| 383 | import abstractadmin |
| 384 | |
| 385 | # Smoke test to determine whether admin site works at all |
| 386 | response = self.client.get('/test_admin/abstractadmin/admin_views/pizza/') |
| 387 | self.failUnlessEqual(response.status_code, 200) |
| 388 | |
| 389 | self.assertRaises(ImproperlyConfigured, abstractadmin.do_register) |
| 390 | |
363 | 391 | def get_perm(Model, perm): |
364 | 392 | """Return the permission object, for the Model""" |
365 | 393 | ct = ContentType.objects.get_for_model(Model) |
diff --git a/tests/regressiontests/admin_views/urls.py b/tests/regressiontests/admin_views/urls.py
index f3f1fbd..b7aeba5 100644
a
|
b
|
from django.conf.urls.defaults import *
|
2 | 2 | from django.contrib import admin |
3 | 3 | import views |
4 | 4 | import customadmin |
| 5 | import abstractadmin |
5 | 6 | |
6 | 7 | urlpatterns = patterns('', |
7 | 8 | (r'^admin/doc/', include('django.contrib.admindocs.urls')), |
8 | 9 | (r'^admin/secure-view/$', views.secure_view), |
9 | 10 | (r'^admin/', include(admin.site.urls)), |
10 | 11 | (r'^admin2/', include(customadmin.site.urls)), |
| 12 | (r'^abstractadmin/', include(abstractadmin.site.urls)), |
11 | 13 | ) |