mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-05-17 20:11:06 +00:00
Merge pull request #100 from skorokithakis/master
Don't crash if the linked object is not in the admin (fixes #99)
This commit is contained in:
commit
1cb1d98827
1 changed files with 7 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ import json
|
|||
|
||||
from django.conf import settings
|
||||
from django.core import urlresolvers
|
||||
from django.urls.exceptions import NoReverseMatch
|
||||
|
||||
MAX = 75
|
||||
|
||||
|
|
@ -26,8 +27,12 @@ class LogEntryAdminMixin(object):
|
|||
def resource_url(self, obj):
|
||||
app_label, model = obj.content_type.app_label, obj.content_type.model
|
||||
viewname = 'admin:%s_%s_change' % (app_label, model)
|
||||
link = urlresolvers.reverse(viewname, args=[obj.object_id or obj.object_pk])
|
||||
return u'<a href="%s">%s</a>' % (link, obj.object_repr)
|
||||
try:
|
||||
link = urlresolvers.reverse(viewname, args=[obj.object_id])
|
||||
except NoReverseMatch:
|
||||
return obj.object_repr
|
||||
else:
|
||||
return u'<a href="%s">%s</a>' % (link, obj.object_repr)
|
||||
resource_url.allow_tags = True
|
||||
resource_url.short_description = 'Resource'
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue