magic-removal: Fixed #1253 -- Got admin doc for models working.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2099 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-01-21 22:41:56 +00:00
parent 882c7c1885
commit b4a454f956
3 changed files with 31 additions and 23 deletions

View File

@ -8,18 +8,19 @@
{% block content %}
<h1>Models Documentation</h1>
<h1>Model documentation</h1>
{% regroup models by app_label as grouped_models %}
<div id="content-main">
{% regroup models|dictsort:"module" by module as grouped_models %}
{% for group in grouped_models %}
<div class="module">
<h2 id='{{ group.grouper }}'>{{ group.grouper }}</h2>
<h2 id="{{ group.grouper }}">{{ group.grouper|capfirst }}</h2>
<table class="xfull">
{% for model in group.list %}
<tr>
<th><a href="{{ model.name }}/">{{ model.class }}</a></th>
<th><a href="{{ model.app_label }}.{{ model.object_name.lower }}/">{{ model.object_name }}</a></th>
</tr>
{% endfor %}
</table>
@ -32,11 +33,11 @@
{% block sidebar %}
<div id="content-related" class="sidebar">
<div class="module">
<h2>Model Groups Quick List</h2>
<h2>Model groups</h2>
<ul>
{% regroup models|dictsort:"module" by module as grouped_models %}
{% regroup models by app_label as grouped_models %}
{% for group in grouped_models %}
<li><a href="#{{ group.grouper }}">{{ group.grouper }}</a></li>
<li><a href="#{{ group.grouper }}">{{ group.grouper|capfirst }}</a></li>
{% endfor %}
</ul>
</div>

View File

@ -17,7 +17,7 @@ urlpatterns = patterns('',
('^doc/views/jump/$', 'django.contrib.admin.views.doc.jump_to_view'),
('^doc/views/(?P<view>[^/]+)/$', 'django.contrib.admin.views.doc.view_detail'),
('^doc/models/$', 'django.contrib.admin.views.doc.model_index'),
('^doc/models/(?P<model>[^/]+)/$', 'django.contrib.admin.views.doc.model_detail'),
('^doc/models/(?P<app_label>[^\.]+)\.(?P<model_name>[^/]+)/$', 'django.contrib.admin.views.doc.model_detail'),
# ('^doc/templates/$', 'django.views.admin.doc.template_index'),
('^doc/templates/(?P<template>.*)/$', 'django.contrib.admin.views.doc.template_detail'),

View File

@ -4,7 +4,7 @@ from django.conf import settings
from django.contrib.admin.views.decorators import staff_member_required
from django.db import models
from django.shortcuts import render_to_response
from django.core.exceptions import ViewDoesNotExist
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
from django.http import Http404
from django.core import urlresolvers
from django.contrib.admin import utils
@ -140,26 +140,30 @@ def model_index(request):
m_list = []
for app in models.get_installed_model_modules():
for model in app._MODELS:
opts = model._meta
m_list.append({
'name': '%s.%s' % (opts.app_label, opts.module_name),
'module': opts.app_label,
'class': opts.module_name,
})
m_list.append(model._meta)
return render_to_response('admin_doc/model_index', {'models': m_list}, context_instance=RequestContext(request))
model_index = staff_member_required(model_index)
def model_detail(request, model):
def model_detail(request, app_label, model_name):
if not utils.docutils_is_available:
return missing_docutils_page(request)
# Get the model class.
try:
model = models.get_app(model)
except ImportError:
raise Http404
opts = model.Klass._meta
app_mod = models.get_app(app_label)
except ImproperlyConfigured:
raise Http404, "App %r not found" % app_label
model = None
for m in app_mod._MODELS:
if m._meta.object_name.lower() == model_name:
model = m
break
if model is None:
raise Http404, "Model %r not found in app %r" % (model_name, app_label)
# Gather fields/field descriptions
opts = model._meta
# Gather fields/field descriptions.
fields = []
for field in opts.fields:
fields.append({
@ -168,8 +172,10 @@ def model_detail(request, model):
'verbose': field.verbose_name,
'help': field.help_text,
})
for func_name, func in model.Klass.__dict__.items():
if callable(func) and len(inspect.getargspec(func)[0]) == 0:
# Gather model methods.
for func_name, func in model.__dict__.items():
if (inspect.isfunction(func) or inspect.ismethod(func)) and len(inspect.getargspec(func)[0]) == 0:
try:
for exclude in MODEL_METHODS_EXCLUDE:
if func_name.startswith(exclude):
@ -184,6 +190,7 @@ def model_detail(request, model):
'data_type': get_return_data_type(func_name),
'verbose': verbose,
})
return render_to_response('admin_doc/model_detail', {
'name': '%s.%s' % (opts.app_label, opts.module_name),
'summary': "Fields on %s objects" % opts.verbose_name,