Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Add utilities for quickly getting the admin url/link for a model inst…
Browse files Browse the repository at this point in the history
…ance.
  • Loading branch information
Greg Turner committed Oct 24, 2016
1 parent 7752dec commit 6639b33
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions icekit/utils/admin/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.contrib.admin.templatetags.admin_urls import admin_urlname
from django.template import Template, Context
from django.utils.safestring import mark_safe


def admin_url(inst):
"""
:param inst: An Model Instance
:return: the admin URL for the instance. Permissions aren't checked.
"""
if inst:
t = Template("""{% load admin_urls %}{% url opts|admin_urlname:'change' inst.pk %}""")
return t.render(Context({ 'inst': inst, 'opts': inst._meta}))
return ""

def admin_link(inst):
"""
:param inst: An Model Instance
:return: a complete admin link for the instance. Permissions aren't checked.
"""
if inst:
t = Template("""{% load admin_urls %}<a href="{% url opts|admin_urlname:'change' inst.pk %}">{{ inst }}</a>""")
return mark_safe(t.render(Context({ 'inst': inst, 'opts': inst._meta})))
return ""

0 comments on commit 6639b33

Please sign in to comment.