Skip to content

Commit

Permalink
object_link() - handle case when content type is None
Browse files Browse the repository at this point in the history
Fixes #21
  • Loading branch information
yprez committed May 1, 2016
1 parent caa8bd4 commit ca5b40b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -4,6 +4,7 @@ Current
* Add tests and support for Django 1.9 and Python 3.5.
* Drop support for Python 2.5, 2.6, Django 1.4, 1.5, 1.6.
* Test with py.test instead of unittest.
* Fix AttributeError when content_type is None.


v0.1.5 - 17/02/2015
Expand Down
7 changes: 4 additions & 3 deletions logentry_admin/admin.py
Expand Up @@ -108,13 +108,14 @@ def has_delete_permission(self, request, obj=None):

def object_link(self, obj):
object_link = escape(obj.object_repr)
content_type = obj.content_type

if obj.action_flag != DELETION:
if obj.action_flag != DELETION and content_type is not None:
# try returning an actual link instead of object repr string
try:
url = reverse(
'admin:{}_{}_change'.format(obj.content_type.app_label,
obj.content_type.model),
'admin:{}_{}_change'.format(content_type.app_label,
content_type.model),
args=[obj.object_id]
)
object_link = '<a href="{}">{}</a>'.format(url, object_link)
Expand Down

0 comments on commit ca5b40b

Please sign in to comment.