Skip to content

Commit

Permalink
Make papertrail admin viewer resilient to the model class referenced …
Browse files Browse the repository at this point in the history
…by the related object not being available
  • Loading branch information
eranrund committed Jan 24, 2017
1 parent 838aa3a commit c26698d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 1.1.3
===========================================================
* Make papertrail admin viewer resilient to the model class referenced
by the related object not being available (this would happen, for example,
when an app is removed from INSTALLED_APPS but it's Content Type object
is still in the database).


Version 1.1.2
===========================================================
* Add default Entry admin
Expand Down
2 changes: 1 addition & 1 deletion papertrail/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.1.2'
__version__ = '1.1.3'
default_app_config = 'papertrail.apps.PapertrailConfig'
8 changes: 8 additions & 0 deletions papertrail/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ class RelatedObject(models.Model):
class Meta:
abstract = True

@property
def safe_related_object(self):
try:
return self.related_object
# This will happen if the model class of this object is not available, for example if the app providing it has been removed from INSTALLED_APPS
except AttributeError:
return None


class EntryRelatedObject(RelatedObject):
entry = models.ForeignKey('Entry', related_name='targets')
Expand Down
4 changes: 2 additions & 2 deletions papertrail/templates/admin/object_papertrail.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
<ul>
{% for target in action.targets.all %}
<li>
<a href="{{ target.related_object|adminview:'change' }}">
{{ target.relation_name }}: {{ target.related_object }}
<a href="{{ target.safe_related_object|adminview:'change' }}">
{{ target.relation_name }}: {{ target.safe_related_object }}
</a>
</li>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='django-papertrail',
version='1.1.2',
version='1.1.3',
packages=['papertrail'],
install_requires=[
'Django>=1.7',
Expand Down

0 comments on commit c26698d

Please sign in to comment.