Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11357: contrib.admindocs now correctly displays many-to-many r…

…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...
commit 923c6755c88f19ad7fc0cd74cf818037f85dfb43 1 parent 422adff
James Bennett authored June 30, 2009

Showing 1 changed file with 17 additions and 1 deletion. Show diff stats Hide diff stats

  1. 18  django/contrib/admindocs/views.py
18  django/contrib/admindocs/views.py
@@ -214,6 +214,22 @@ def model_detail(request, app_label, model_name):
214 214
             'help_text': field.help_text,
215 215
         })
216 216
 
  217
+    # Gather many-to-many fields.
  218
+    for field in opts.many_to_many:
  219
+        data_type = related_object_name = field.rel.to.__name__
  220
+        app_label = field.rel.to._meta.app_label
  221
+        verbose = _("related `%(app_label)s.%(object_name)s` objects") % {'app_label': app_label, 'object_name': data_type}
  222
+        fields.append({
  223
+            'name': "%s.all" % field.name,
  224
+            "data_type": 'List',
  225
+            'verbose': utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.module_name),
  226
+        })
  227
+        fields.append({
  228
+            'name'      : "%s.count" % field.name,
  229
+            'data_type' : 'Integer',
  230
+            'verbose'   : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.module_name),
  231
+        })
  232
+
217 233
     # Gather model methods.
218 234
     for func_name, func in model.__dict__.items():
219 235
         if (inspect.isfunction(func) and len(inspect.getargspec(func)[0]) == 1):
@@ -233,7 +249,7 @@ def model_detail(request, app_label, model_name):
233 249
             })
234 250
 
235 251
     # Gather related objects
236  
-    for rel in opts.get_all_related_objects():
  252
+    for rel in opts.get_all_related_objects() + opts.get_all_related_many_to_many_objects():
237 253
         verbose = _("related `%(app_label)s.%(object_name)s` objects") % {'app_label': rel.opts.app_label, 'object_name': rel.opts.object_name}
238 254
         accessor = rel.get_accessor_name()
239 255
         fields.append({

0 notes on commit 923c675

Please sign in to comment.
Something went wrong with that request. Please try again.