From ac5032f1c2c30039b93a4782b2fec9f2bb1aeb86 Mon Sep 17 00:00:00 2001 From: Erik Stein Date: Fri, 21 Sep 2018 11:02:08 +0200 Subject: [PATCH] get_admin_url in debug_utils --- CHANGES | 3 +++ shared/utils/templatetags/debug_utils.py | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 23a307e..499eb61 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +0.2.8 2018-09-21 +- get_admin_url in debug_utils + 0.2.7 2018-09-04 - Make sure the slug field is never empty. - Allow function in AutoSlugfield populate_from. diff --git a/shared/utils/templatetags/debug_utils.py b/shared/utils/templatetags/debug_utils.py index bd2ac8f..6c71815 100644 --- a/shared/utils/templatetags/debug_utils.py +++ b/shared/utils/templatetags/debug_utils.py @@ -1,24 +1,32 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -# Erik Stein , 2009-2017 + +from django import template +from django.contrib.contenttypes.models import ContentType +from django.urls import reverse + try: import ipdb - from django import template - register = template.Library() - @register.filter def ipdb_inspect(value): ipdb.set_trace() return value - @register.simple_tag def ipdb_set_breakpoint(): ipdb.set_trace() -except: - pass \ No newline at end of file +except: # TODO ImportError + pass + + +@register.filter +def get_admin_url(obj): + content_type = ContentType.objects.get_for_model(obj.__class__) + return reverse("admin:%s_%s_change" % (content_type.app_label, content_type.model), args=(obj.id,)) + +