Skip to content

Commit

Permalink
Fixed #11357: contrib.admindocs now correctly displays many-to-many r…
Browse files Browse the repository at this point in the history
…elationships. Thanks to Ben Spaulding for the final version of the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11127 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
ubernostrum committed Jun 30, 2009
1 parent 422adff commit 923c675
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion django/contrib/admindocs/views.py
Expand Up @@ -214,6 +214,22 @@ def model_detail(request, app_label, model_name):
'help_text': field.help_text,
})

# Gather many-to-many fields.
for field in opts.many_to_many:
data_type = related_object_name = field.rel.to.__name__
app_label = field.rel.to._meta.app_label
verbose = _("related `%(app_label)s.%(object_name)s` objects") % {'app_label': app_label, 'object_name': data_type}
fields.append({
'name': "%s.all" % field.name,
"data_type": 'List',
'verbose': utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.module_name),
})
fields.append({
'name' : "%s.count" % field.name,
'data_type' : 'Integer',
'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.module_name),
})

# Gather model methods.
for func_name, func in model.__dict__.items():
if (inspect.isfunction(func) and len(inspect.getargspec(func)[0]) == 1):
Expand All @@ -233,7 +249,7 @@ def model_detail(request, app_label, model_name):
})

# Gather related objects
for rel in opts.get_all_related_objects():
for rel in opts.get_all_related_objects() + opts.get_all_related_many_to_many_objects():
verbose = _("related `%(app_label)s.%(object_name)s` objects") % {'app_label': rel.opts.app_label, 'object_name': rel.opts.object_name}
accessor = rel.get_accessor_name()
fields.append({
Expand Down

0 comments on commit 923c675

Please sign in to comment.