Skip to content

Commit

Permalink
add default Entry admin
Browse files Browse the repository at this point in the history
  • Loading branch information
eranrund committed Aug 16, 2016
1 parent 0690959 commit fe7ee9e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 1.1.2
===========================================================
* Add default Entry admin


Version 1.1.1
===========================================================
* Add a new `data_adapter` argument to `papertrail.log`. The method
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.1'
__version__ = '1.1.2'
default_app_config = 'papertrail.apps.PapertrailConfig'
31 changes: 30 additions & 1 deletion papertrail/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
import json

from django.conf.urls import url
from django.contrib import admin
from django.core import serializers
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.shortcuts import get_object_or_404, render
from django.utils.encoding import force_text
from django.utils.html import format_html
from django.utils.text import capfirst
from django.utils.translation import ugettext as _

import papertrail
from papertrail.models import Entry
from papertrail.models import Entry, EntryRelatedObject


def admin_reverse_for_model(model):
return reverse('admin:{}_{}_change'.format(model._meta.app_label, model._meta.model_name), args=[model.id])


class AdminEventLoggerMixin(object):
Expand Down Expand Up @@ -238,3 +245,25 @@ def add_related_change(changes, obj, action='change', fields=None):
add_related_change(changes, obj, action='add')

return json.dumps(changes)


class EntryRelatedObjectInline(admin.StackedInline):
model = EntryRelatedObject
extra = 0
fields = ('relation_name', 'related_content_type', 'related_model', )
readonly_fields = ('related_model', )

def related_model(self, obj):
related_obj = obj.related_object
return format_html(
u'<a href="{}">{}</a>',
admin_reverse_for_model(related_obj),
related_obj,
)


@admin.register(Entry)
class EntryAdmin(admin.ModelAdmin):
list_display = ('type', 'message', 'timestamp', )
search_fields = ('type', )
inlines = (EntryRelatedObjectInline, )
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.1',
version='1.1.2',
packages=['papertrail'],
install_requires=[
'Django>=1.7',
Expand Down

0 comments on commit fe7ee9e

Please sign in to comment.