From 923c6755c88f19ad7fc0cd74cf818037f85dfb43 Mon Sep 17 00:00:00 2001 From: James Bennett Date: Tue, 30 Jun 2009 18:40:29 +0000 Subject: [PATCH] Fixed #11357: contrib.admindocs now correctly displays many-to-many relationships. 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 --- django/contrib/admindocs/views.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py index f66ea3e9b0..4f22fe0a0a 100644 --- a/django/contrib/admindocs/views.py +++ b/django/contrib/admindocs/views.py @@ -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): @@ -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({