Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add url reverse support in admin #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions mlogger/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,34 @@

from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

from django.utils.safestring import mark_safe
from django.core.urlresolvers import reverse
from mlogger.models import Log

class __Log(admin.ModelAdmin):

class AdminLog(admin.ModelAdmin):
list_display = ('user', 'action', 'content_type', 'timestamp')
admin.site.register(Log, __Log)
readonly_fields = ('user', 'action', '_object', 'data', 'timestamp')
exclude = ('content_type', 'oid', )

def _object(self, object):
app_label = object.content_type.app_label
model = object.content_type.model
oid = object.oid
text = u'{app_label}.{model}:{oid}'.format(app_label=app_label,
model=model,
oid=oid)
url = u'#'
if object.action in ('create', 'update'):
try:
url = reverse('admin:{app_label}_{model}_change'.\
format(app_label=app_label,
model=model), args=[oid])
except:
pass
return u'<a href="{url}">{text}</a>'.format(url=url, text=text)
_object.allow_tags = True
_object.short_description = _('object')

admin.site.register(Log, AdminLog)
Log.description = _(u'This model consists of all meaningful events of system.')