From ea83102d0f0c215ae2bd16a2c8c474ce615bad9a Mon Sep 17 00:00:00 2001 From: Vajrasky Kok Date: Sat, 7 Dec 2013 15:13:20 +0800 Subject: [PATCH] Fixed #21319 -- Added documentation for the Form.fields attribute. Thanks pydanny for the report. Also, added documentation about base_fields attribute and its difference with fields attribute. --- docs/ref/forms/api.txt | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index ef4da9479e5..c8f302b9249 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -205,6 +205,40 @@ precedence:: Url: Comment: +Accessing the fields from the form +---------------------------------- + +.. attribute:: Form.fields + +You can access the fields of :class:`Form` instance from its ``fields`` +attribute:: + + >>> for row in f.fields.values(): print(row) + ... + + + + >>> f.fields['name'] + + +You can alter the field of :class:`Form` instance to change the way it is +presented in the form:: + + >>> f.as_table().split('\n')[0] + 'Name:' + >>> f.fields['name'].label = "Username" + >>> f.as_table().split('\n')[0] + 'Username:' + +Beware not to alter the ``base_fields`` attribute because this modification +will influence all subsequent ``ContactForm`` instances within the same Python +process:: + + >>> f.base_fields['name'].label = "Username" + >>> another_f = CommentForm(auto_id=False) + >>> another_f.as_table().split('\n')[0] + 'Username:' + Accessing "clean" data ----------------------