Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added some helpful hints to list_display documentation in docs/model-…

…api.txt

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3652 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2836624ba44ffc3d4d88794f59599f249ae87442 1 parent 3460943
Adrian Holovaty authored August 23, 2006

Showing 1 changed file with 16 additions and 3 deletions. Show diff stats Hide diff stats

  1. 19  docs/model-api.txt
19  docs/model-api.txt
@@ -1222,10 +1222,13 @@ A few special cases to note about ``list_display``:
1222 1222
       of the related object.
1223 1223
 
1224 1224
     * ``ManyToManyField`` fields aren't supported, because that would entail
1225  
-        executing a separate SQL statement for each row in the table.
  1225
+      executing a separate SQL statement for each row in the table. If you
  1226
+      want to do this nonetheless, give your model a custom method, and add
  1227
+      that method's name to ``list_display``. (See below for more on custom
  1228
+      methods in ``list_display``.)
1226 1229
 
1227  
-    * If the field is a ``BooleanField``, Django will display a pretty "on" or
1228  
-      "off" icon instead of ``True`` or ``False``.
  1230
+    * If the field is a ``BooleanField`` or ``NullBooleanField``, Django will
  1231
+      display a pretty "on" or "off" icon instead of ``True`` or ``False``.
1229 1232
 
1230 1233
     * If the string given is a method of the model, Django will call it and
1231 1234
       display the output. This method should have a ``short_description``
@@ -1262,6 +1265,16 @@ A few special cases to note about ``list_display``:
1262 1265
                   return '<span style="color: #%s;">%s %s</span>' % (self.color_code, self.first_name, self.last_name)
1263 1266
               colored_name.allow_tags = True
1264 1267
 
  1268
+    * The ``__str__()`` method is just as valid in ``list_display`` as any
  1269
+      other model method, so it's perfectly OK to do this::
  1270
+
  1271
+          list_display = ('__str__', 'some_other_field')
  1272
+
  1273
+    * For any element of ``list_display`` that is not a field on the model, the
  1274
+      change list page will not allow ordering by that column. This is because
  1275
+      ordering is done at the database level, and Django has no way of knowing
  1276
+      how to order the result of a custom method at the SQL level.
  1277
+
1265 1278
 ``list_display_links``
1266 1279
 ----------------------
1267 1280
 

0 notes on commit 2836624

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