diff --git a/django/conf/admin_templates/index.html b/django/conf/admin_templates/index.html index a4098b86d77..5149f255809 100644 --- a/django/conf/admin_templates/index.html +++ b/django/conf/admin_templates/index.html @@ -6,6 +6,24 @@ {% block content %}
+{% load adminapplist %} + +{% get_admin_app_list as app_list %} +{% for app in app_list %} +
+

{{ app.name }}

+ + {% for model in app.models %} + + + + + + {% endfor %} +
{{ model.name }}AddChange
+
+{% endfor %} +
{% endblock %} diff --git a/django/templatetags/adminapplist.py b/django/templatetags/adminapplist.py new file mode 100644 index 00000000000..069fb4529b9 --- /dev/null +++ b/django/templatetags/adminapplist.py @@ -0,0 +1,34 @@ +from django.core import template + +class AdminApplistNode(template.Node): + def __init__(self, varname): + self.varname = varname + + def render(self, context): + from django.core import meta + app_list = [] + for app in meta.get_installed_model_modules(): + app_label = app.__name__[app.__name__.rindex('.')+1:] + model_list = [{'name': meta.capfirst(m._meta.verbose_name_plural), + 'admin_url': '%s/%s/' % (app_label, m._meta.module_name)} \ + for m in app._MODELS if m._meta.admin] + if model_list: + app_list.append({ + 'name': app_label.title(), + 'models': model_list, + }) + context[self.varname] = app_list + return '' + +def get_admin_app_list(parser, token): + """ + {% get_admin_app_list as app_list %} + """ + tokens = token.contents.split() + if len(tokens) < 3: + raise template.TemplateSyntaxError, "'%s' tag requires two arguments" % tokens[0] + if tokens[1] != 'as': + raise template.TemplateSyntaxError, "First argument to '%s' tag must be 'as'" % tokens[0] + return AdminApplistNode(tokens[2]) + +template.register_tag('get_admin_app_list', get_admin_app_list)