don't create selflink if no modeladmin exists for that model
diff --git a/planetstack/core/admin.py b/planetstack/core/admin.py
index 77fa744..3a13945 100644
--- a/planetstack/core/admin.py
+++ b/planetstack/core/admin.py
@@ -14,7 +14,7 @@
from django.contrib.contenttypes import generic
from suit.widgets import LinkedSelect
from django.core.exceptions import PermissionDenied
-from django.core.urlresolvers import reverse
+from django.core.urlresolvers import reverse, NoReverseMatch
import django_evolution
@@ -78,6 +78,17 @@
# the selflink field, we override __init__ to modify self.fields and
# self.readonly_fields.
+ self.setup_selflink()
+
+ def setup_selflink(self):
+ reverse_path = "admin:%s_change" % (self.model._meta.db_table)
+ try:
+ url = reverse(reverse_path, args=(0,))
+ except NoReverseMatch:
+ # We don't have an admin for this object, so don't create the
+ # selflink.
+ return
+
if (self.fields is None):
self.fields = []
for f in self.model._meta.fields:
@@ -94,11 +105,11 @@
def selflink(self, obj):
if obj.id:
- reverse_path = "admin:%s_change" % (self.model._meta.db_table)
- url = reverse(reverse_path, args =(obj.id,))
+ reverse_path = "admin:%s_change" % (self.model._meta.db_table)
+ url = reverse(reverse_path, args =(obj.id,))
return "<a href='%s'>Details</a>" % str(url)
else:
- return "Not present"
+ return "Not present"
selflink.allow_tags = True
selflink.short_description = "Details"