Code

Ticket #3287: admin_boolean_docs.diff

File admin_boolean_docs.diff, 1.1 KB (added by xian@…, 7 years ago)

diff to add boolean=True info to the model creation docs

Line 
1Index: docs/model-api.txt
2===================================================================
3--- docs/model-api.txt  (revision 4306)
4+++ docs/model-api.txt  (working copy)
5@@ -1268,6 +1268,24 @@
6                   return '<span style="color: #%s;">%s %s</span>' % (self.color_code, self.first_name, self.last_name)
7               colored_name.allow_tags = True
8 
9+    * If the string given is a method of the model that returns True or False
10+      Django will display a pretty "on" or "off" icon if you give the method a
11+      ``boolean`` attribute whose value is ``True``.
12+
13+      Here's a full example model::
14+
15+          class Person(models.Model):
16+              first_name = models.CharField(maxlength=50)
17+              birthday = models.DateField()
18+
19+              class Admin:
20+                  list_display = ('name', 'born_in_fifties')
21+
22+              def born_in_fifties(self):
23+                  return self.birthday.strftime('%Y')[:3] == 5
24+              born_in_fifties.boolean = True
25+
26+
27     * The ``__str__()`` method is just as valid in ``list_display`` as any
28       other model method, so it's perfectly OK to do this::
29