Skip to content

Instantly share code, notes, and snippets.

@rctay
Created July 9, 2010 08:07
Show Gist options
  • Save rctay/469214 to your computer and use it in GitHub Desktop.
Save rctay/469214 to your computer and use it in GitHub Desktop.
[django] admin view wrapper cum url() factory method
"""
Wraps a view in AdminSite.admin_view() and returns a url() tuple constructed
from the view's name.
"""
from django.conf.urls.defaults import url
def wrap_admin_view(modeladmin, view_func):
view = view_func.__name__
meta = modeladmin.model._meta
return url(
r'^%s/$' % view,
modeladmin.admin_site.admin_view(view_func),
name='%s_%s_%s' % (meta.app_label, meta.module_name, view),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment