Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.0.X] Fixed #11357: contrib.admindocs now correctly displays many-t…

…o-many relationships. Thanks to Ben Spaulding for the final version of the patch.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@11128 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2a7b781cfee2f81ce808a56b13df4cedaad14d8c 1 parent 8fd4000
James Bennett ubernostrum authored
Showing with 17 additions and 1 deletion.
  1. +17 −1 django/contrib/admindocs/views.py
18 django/contrib/admindocs/views.py
View
@@ -213,6 +213,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):
@@ -232,7 +248,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({
Please sign in to comment.
Something went wrong with that request. Please try again.