Permalink
Browse files

Update the example app to demonstrate the polymorphic admin

This really begs for a separate folder, but I leave that to a new commit
for now.
  • Loading branch information...
1 parent 42d525a commit a6d62ed63066634f1bfd400e4207a14c63873f5c @vdboor vdboor committed Jul 13, 2012
Showing with 84 additions and 4 deletions.
  1. +63 −0 pexp/admin.py
  2. +11 −4 settings.py
  3. +10 −0 urls.py
View
@@ -0,0 +1,63 @@
+from django.contrib import admin
+from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin
+from pexp.models import *
+
+
+class ProjectChildAdmin(PolymorphicChildModelAdmin):
+ base_model = Project
+
+class ProjectAdmin(PolymorphicParentModelAdmin):
+ base_model = Project
+ child_models = (
+ (Project, ProjectChildAdmin),
+ (ArtProject, ProjectChildAdmin),
+ (ResearchProject, ProjectChildAdmin),
+ )
+
+admin.site.register(Project, ProjectAdmin)
+
+
+
+class ModelAChildAdmin(PolymorphicChildModelAdmin):
+ base_model = ModelA
+
+class ModelAAdmin(PolymorphicParentModelAdmin):
+ base_model = ModelA
+ child_models = (
+ (ModelA, ModelAChildAdmin),
+ (ModelB, ModelAChildAdmin),
+ (ModelC, ModelAChildAdmin),
+ )
+
+admin.site.register(ModelA, ModelAAdmin)
+
+
+if 'Model2A' in globals():
+ class Model2AChildAdmin(PolymorphicChildModelAdmin):
+ base_model = Model2A
+
+ class Model2AAdmin(PolymorphicParentModelAdmin):
+ base_model = Model2A
+ child_models = (
+ (Model2A, Model2AChildAdmin),
+ (Model2B, Model2AChildAdmin),
+ (Model2C, Model2AChildAdmin),
+ )
+
+ admin.site.register(Model2A, Model2AAdmin)
+
+
+if 'UUIDModelA' in globals():
+ class UUIDModelAChildAdmin(PolymorphicChildModelAdmin):
+ base_model = UUIDModelA
+
+ class UUIDModelAAdmin(PolymorphicParentModelAdmin):
+ base_model = UUIDModelA
+ child_models = (
+ (UUIDModelA, UUIDModelAChildAdmin),
+ (UUIDModelB, UUIDModelAChildAdmin),
+ (UUIDModelC, UUIDModelAChildAdmin),
+ )
+
+ admin.site.register(UUIDModelA, UUIDModelAAdmin)
+
View
@@ -77,9 +77,12 @@
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
)
-ROOT_URLCONF = ''
+ROOT_URLCONF = 'urls'
+STATIC_URL = '/static/'
+ADMIN_MEDIA_PREFIX = '/static/admin/' # 1.3 compatibility
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
@@ -88,10 +91,14 @@
)
INSTALLED_APPS = (
- #'django.contrib.auth',
+ 'django.contrib.auth',
+ 'django.contrib.admin',
'django.contrib.contenttypes',
- #'django.contrib.sessions',
+ 'django.contrib.messages',
+ 'django.contrib.sessions',
+ 'django.contrib.staticfiles',
+
#'django.contrib.sites',
- 'polymorphic', # only needed if you want to use polymorphic_dumpdata
+ 'polymorphic', # needed if you want to use the polymorphic admin
'pexp', # this Django app is for testing and experimentation; not needed otherwise
)
View
@@ -0,0 +1,10 @@
+from django.conf import settings
+from django.conf.urls.defaults import patterns, include, url
+from django.conf.urls.static import static
+from django.contrib import admin
+
+admin.autodiscover()
+
+urlpatterns = patterns('',
+ url(r'^admin/', include(admin.site.urls)),
+)

0 comments on commit a6d62ed

Please sign in to comment.