From 6645d1fe48868814e4c73056b68be5c3861ed2d0 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Thu, 2 Nov 2006 03:16:12 +0000 Subject: [PATCH] Added ChoiceField, MultipleChoiceField to django.newforms git-svn-id: http://code.djangoproject.com/svn/django/trunk@3959 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/newforms/__init__.py | 1 - django/newforms/fields.py | 56 ++++++++++++++- tests/regressiontests/forms/tests.py | 100 +++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 2 deletions(-) diff --git a/django/newforms/__init__.py b/django/newforms/__init__.py index f0eca9a950..9d12c55ae9 100644 --- a/django/newforms/__init__.py +++ b/django/newforms/__init__.py @@ -3,7 +3,6 @@ Django validation and HTML form handling. TODO: Validation not tied to a particular field - ' >>> f['message'].as_text() u'' +For a form with a + + + +>>> f = FrameworkForm({'name': 'Django', 'language': 'P'}) +>>> print f['language'] + + +MultipleChoiceField is a special case, as its data is required to be a list: +>>> class SongForm(Form): +... name = CharField() +... composers = MultipleChoiceField() +>>> f = SongForm() +>>> print f['composers'] + +>>> class SongForm(Form): +... name = CharField() +... composers = MultipleChoiceField(choices=[('J', 'John Lennon'), ('P', 'Paul McCartney')]) +>>> f = SongForm() +>>> print f['composers'] + +>>> f = SongForm({'name': 'Yesterday', 'composers': ['P']}) +>>> print f['name'] + +>>> print f['composers'] + """ if __name__ == "__main__":