From 4c1509a62a83167637c8b3fb885334c600ebd7d9 Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Fri, 4 Nov 2011 01:54:30 -0700 Subject: [PATCH] Updated docs re choices [#284] [#314] --- docs/guide/defining-documents.rst | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/guide/defining-documents.rst b/docs/guide/defining-documents.rst index 6367d95a..730d180f 100644 --- a/docs/guide/defining-documents.rst +++ b/docs/guide/defining-documents.rst @@ -135,7 +135,28 @@ arguments can be set on all fields: When True, use this field as a primary key for the collection. :attr:`choices` (Default: None) - An iterable of choices to which the value of this field should be limited. + An iterable (e.g. a list or tuple) of choices to which the value of this + field should be limited. + + Can be either be a nested tuples of value (stored in mongo) and a + human readable key :: + + SIZE = (('S', 'Small'), + ('M', 'Medium'), + ('L', 'Large'), + ('XL', 'Extra Large'), + ('XXL', 'Extra Extra Large')) + + + class Shirt(Document): + size = StringField(max_length=3, choices=SIZE) + + Or a flat iterable just containing values :: + + SIZE = ('S', 'M', 'L', 'XL', 'XXL') + + class Shirt(Document): + size = StringField(max_length=3, choices=SIZE) :attr:`help_text` (Default: None) Optional help text to output with the field - used by form libraries