mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Fixed #5405 -- Added admindocs support for reStructured text in model docstrings
Thanks elvard and gkmngrgn for work on the patch and Markus H. for review.
This commit is contained in:
@@ -22,11 +22,10 @@
|
||||
|
||||
{% block content %}
|
||||
<div id="content-main">
|
||||
<h1>{{ summary }}</h1>
|
||||
<h1>{{ name }}</h1>
|
||||
<h2 class="subhead">{{ summary }}</h2>
|
||||
|
||||
{% if description %}
|
||||
<p>{% filter linebreaksbr %}{% trans description %}{% endfilter %}</p>
|
||||
{% endif %}
|
||||
{{ description }}
|
||||
|
||||
<div class="module">
|
||||
<table class="model">
|
||||
|
||||
@@ -178,18 +178,25 @@ class ModelDetailView(BaseAdminDocsView):
|
||||
template_name = 'admin_doc/model_detail.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
model_name = self.kwargs['model_name']
|
||||
# Get the model class.
|
||||
try:
|
||||
app_config = apps.get_app_config(self.kwargs['app_label'])
|
||||
except LookupError:
|
||||
raise Http404(_("App %(app_label)r not found") % self.kwargs)
|
||||
try:
|
||||
model = app_config.get_model(self.kwargs['model_name'])
|
||||
model = app_config.get_model(model_name)
|
||||
except LookupError:
|
||||
raise Http404(_("Model %(model_name)r not found in app %(app_label)r") % self.kwargs)
|
||||
|
||||
opts = model._meta
|
||||
|
||||
title, body, metadata = utils.parse_docstring(model.__doc__)
|
||||
if title:
|
||||
title = utils.parse_rst(title, 'model', _('model:') + model_name)
|
||||
if body:
|
||||
body = utils.parse_rst(body, 'model', _('model:') + model_name)
|
||||
|
||||
# Gather fields/field descriptions.
|
||||
fields = []
|
||||
for field in opts.fields:
|
||||
@@ -271,9 +278,8 @@ class ModelDetailView(BaseAdminDocsView):
|
||||
})
|
||||
kwargs.update({
|
||||
'name': '%s.%s' % (opts.app_label, opts.object_name),
|
||||
# Translators: %s is an object type name
|
||||
'summary': _("Attributes on %s objects") % opts.object_name,
|
||||
'description': model.__doc__,
|
||||
'summary': title,
|
||||
'description': body,
|
||||
'fields': fields,
|
||||
})
|
||||
return super(ModelDetailView, self).get_context_data(**kwargs)
|
||||
|
||||
Reference in New Issue
Block a user