Changeset 8020 for django/trunk/docs
- Timestamp:
- 07/21/08 11:38:54 (6 months ago)
- Files:
-
- django/trunk/docs/add_ons.txt (modified) (1 diff)
- django/trunk/docs/api_stability.txt (modified) (1 diff)
- django/trunk/docs/authentication.txt (modified) (2 diffs)
- django/trunk/docs/custom_model_fields.txt (modified) (2 diffs)
- django/trunk/docs/form_for_model.txt (modified) (5 diffs)
- django/trunk/docs/form_preview.txt (modified) (2 diffs)
- django/trunk/docs/forms.txt (moved) (moved from django/trunk/docs/newforms.txt) (12 diffs)
- django/trunk/docs/form_wizard.txt (modified) (7 diffs)
- django/trunk/docs/generic_views.txt (modified) (1 diff)
- django/trunk/docs/index.txt (modified) (1 diff)
- django/trunk/docs/localflavor.txt (modified) (4 diffs)
- django/trunk/docs/model-api.txt (modified) (1 diff)
- django/trunk/docs/modelforms.txt (modified) (5 diffs)
- django/trunk/docs/oldforms.txt (copied) (copied from django/trunk/docs/forms.txt) (5 diffs)
- django/trunk/docs/upload_handling.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/add_ons.txt
r7294 r8020 77 77 ========= 78 78 79 A set of high-level abstractions for Django forms (django. newforms).79 A set of high-level abstractions for Django forms (django.forms). 80 80 81 81 django.contrib.formtools.preview django/trunk/docs/api_stability.txt
r7294 r8020 116 116 .. _transactions: ../transactions/ 117 117 .. _url dispatch: ../url_dispatch/ 118 .. _forms and validation: ../ forms/118 .. _forms and validation: ../oldforms/ 119 119 .. _serialization: ../serialization/ 120 120 .. _authentication: ../authentication/ django/trunk/docs/authentication.txt
r7967 r8020 518 518 519 519 * ``form``: A ``Form`` object representing the login form. See the 520 ` newforms documentation`_ for more on ``Form`` objects.520 `forms documentation`_ for more on ``FormWrapper`` objects. 521 521 * ``next``: The URL to redirect to after successful login. This may contain 522 522 a query string, too. … … 558 558 {% endblock %} 559 559 560 .. _ newforms documentation: ../newforms/560 .. _forms documentation: ../forms/ 561 561 .. _site framework docs: ../sites/ 562 562 django/trunk/docs/custom_model_fields.txt
r7967 r8020 112 112 of the class behavior. 113 113 114 .. _form fields: ../ newforms/#fields114 .. _form fields: ../forms/#fields 115 115 116 116 It's important to realize that a Django field class is not what is stored in … … 494 494 fields. 495 495 496 .. _helper functions: ../ newforms/#generating-forms-for-models497 .. _forms documentation: ../ newforms/496 .. _helper functions: ../forms/#generating-forms-for-models 497 .. _forms documentation: ../forms/ 498 498 499 499 ``get_internal_type(self)`` django/trunk/docs/form_for_model.txt
r7294 r8020 21 21 -------------------- 22 22 23 The method ``django. newforms.form_for_model()`` creates a form based on the23 The method ``django.forms.form_for_model()`` creates a form based on the 24 24 definition of a specific model. Pass it the model class, and it will return a 25 25 ``Form`` class that contains a form field for each model field. … … 27 27 For example:: 28 28 29 >>> from django. newforms import form_for_model29 >>> from django.forms import form_for_model 30 30 31 31 # Create the form class. … … 94 94 types are special cases: 95 95 96 * ``ForeignKey`` is represented by ``django. newforms.ModelChoiceField``,96 * ``ForeignKey`` is represented by ``django.forms.ModelChoiceField``, 97 97 which is a ``ChoiceField`` whose choices are a model ``QuerySet``. 98 98 99 99 * ``ManyToManyField`` is represented by 100 ``django. newforms.ModelMultipleChoiceField``, which is a100 ``django.forms.ModelMultipleChoiceField``, which is a 101 101 ``MultipleChoiceField`` whose choices are a model ``QuerySet``. 102 102 … … 229 229 230 230 If you want to add custom methods to the form generated by 231 ``form_for_model()``, write a class that extends ``django. newforms.BaseForm``231 ``form_for_model()``, write a class that extends ``django.forms.BaseForm`` 232 232 and contains your custom methods. Then, use the ``form`` argument to 233 233 ``form_for_model()`` to tell it to use your custom form as its base class. … … 413 413 form field. 414 414 415 .. _contact form: ../ newforms/#simple-view-example416 .. _`simple example view`: ../ newforms/#simple-view-example415 .. _contact form: ../forms/#simple-view-example 416 .. _`simple example view`: ../forms/#simple-view-example 417 417 418 418 When should you use ``form_for_model()`` and ``form_for_instance()``? django/trunk/docs/form_preview.txt
r7675 r8020 14 14 ========= 15 15 16 Given a ``django. newforms.Form`` subclass that you define, this application16 Given a ``django.forms.Form`` subclass that you define, this application 17 17 takes care of the following workflow: 18 18 … … 66 66 from myapp.preview import SomeModelFormPreview 67 67 from myapp.models import SomeModel 68 from django import newforms asforms68 from django import forms 69 69 70 70 ...and add the following line to the appropriate model in your URLconf:: django/trunk/docs/forms.txt
r7978 r8020 1 ==================== 2 The newforms library 3 ==================== 4 5 ``django.newforms`` is Django's fantastic new form-handling library. It's a 6 replacement for ``django.forms``, the old form/manipulator/validation 7 framework. This document explains how to use this new library. 1 ================= 2 The forms library 3 ================= 4 5 ``django.forms`` is Django's fantastic new form-handling library. It's a 6 replacement for the old form/manipulator/validation framework, which has been 7 moved to ``django.oldforms``. This document explains how to use this new 8 library. 8 9 9 10 Migration plan … … 55 56 ======== 56 57 57 As with the ``django. forms`` ("manipulators") system before it,58 ``django. newforms`` is intended to handle HTML form display, data processing58 As with the ``django.oldforms`` ("manipulators") system before it, 59 ``django.forms`` is intended to handle HTML form display, data processing 59 60 (validation) and redisplay. It's what you use if you want to perform 60 61 server-side validation for an HTML form. … … 89 90 ============ 90 91 91 The primary way of using the `` newforms`` library is to create a form object.92 Do this by subclassing ``django. newforms.Form`` and specifying the form's92 The primary way of using the ``forms`` library is to create a form object. 93 Do this by subclassing ``django.forms.Form`` and specifying the form's 93 94 fields, in a declarative style that you'll be familiar with if you've used 94 95 Django database models. In this section, we'll iteratively develop a form … … 98 99 Start with this basic ``Form`` subclass, which we'll call ``ContactForm``:: 99 100 100 from django import newforms asforms101 from django import forms 101 102 102 103 class ContactForm(forms.Form): … … 585 586 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 586 587 587 By default, forms use ``django. newforms.util.ErrorList`` to format validation588 By default, forms use ``django.forms.util.ErrorList`` to format validation 588 589 errors. If you'd like to use an alternate class for displaying errors, you can 589 590 pass that in at construction time:: 590 591 591 >>> from django. newforms.util import ErrorList592 >>> from django.forms.util import ErrorList 592 593 >>> class DivErrorList(ErrorList): 593 594 ... def __unicode__(self): … … 784 785 785 786 Note that we check ``field.field.required`` and not ``field.required``. In the 786 template, ``field`` is a `` newforms.forms.BoundField`` instance, which holds787 template, ``field`` is a ``forms.forms.BoundField`` instance, which holds 787 788 the actual ``Field`` instance in its ``field`` attribute. 788 789 … … 919 920 you can also instantiate them and use them directly to get a better idea of 920 921 how they work. Each ``Field`` instance has a ``clean()`` method, which takes 921 a single argument and either raises a ``django. newforms.ValidationError``922 a single argument and either raises a ``django.forms.ValidationError`` 922 923 exception or returns the clean value:: 923 924 … … 934 935 If you've used Django's old forms/validation framework, take care in noticing 935 936 this ``ValidationError`` is different than the previous ``ValidationError``. 936 This one lives at ``django. newforms.ValidationError`` rather than937 This one lives at ``django.forms.ValidationError`` rather than 937 938 ``django.core.validators.ValidationError``. 938 939 … … 1186 1187 -------------------------- 1187 1188 1188 Naturally, the `` newforms`` library comes with a set of ``Field`` classes that1189 Naturally, the ``forms`` library comes with a set of ``Field`` classes that 1189 1190 represent common validation needs. This section documents each built-in field. 1190 1191 … … 1589 1590 If the built-in ``Field`` classes don't meet your needs, you can easily create 1590 1591 custom ``Field`` classes. To do this, just create a subclass of 1591 ``django. newforms.Field``. Its only requirements are that it implement a1592 ``django.forms.Field``. Its only requirements are that it implement a 1592 1593 ``clean()`` method and that its ``__init__()`` method accept the core arguments 1593 1594 mentioned above (``required``, ``label``, ``initial``, ``widget``, … … 1680 1681 ``is_valid_email()``. The full class:: 1681 1682 1682 from django import newforms asforms1683 from django import forms 1683 1684 1684 1685 class MultiEmailField(forms.Field): … … 2516 2517 That's all the documentation for now. For more, see the file 2517 2518 http://code.djangoproject.com/browser/django/trunk/tests/regressiontests/forms 2518 -- the unit tests for ``django. newforms``. This can give you a good idea of2519 -- the unit tests for ``django.forms``. This can give you a good idea of 2519 2520 what's possible. (Each submodule there contains separate tests.) 2520 2521 django/trunk/docs/form_wizard.txt
r7294 r8020 18 18 19 19 .. _explained on Wikipedia: http://en.wikipedia.org/wiki/Wizard_%28software%29 20 .. _forms: ../ newforms/20 .. _forms: ../forms/ 21 21 22 22 How it works … … 42 42 just have to do these things: 43 43 44 1. Define a number of ``django. newforms`` ``Form`` classes -- one per wizard44 1. Define a number of ``django.forms`` ``Form`` classes -- one per wizard 45 45 page. 46 46 2. Create a ``FormWizard`` class that specifies what to do once all of your … … 56 56 57 57 The first step in creating a form wizard is to create the ``Form`` classes. 58 These should be standard ``django. newforms`` ``Form`` classes, covered in the59 ` newforms documentation`_.58 These should be standard ``django.forms`` ``Form`` classes, covered in the 59 `forms documentation`_. 60 60 61 61 These classes can live anywhere in your codebase, but convention is to put them … … 66 66 the message itself. Here's what the ``forms.py`` might look like:: 67 67 68 from django import newforms asforms68 from django import forms 69 69 70 70 class ContactForm1(forms.Form): … … 79 79 last one. 80 80 81 .. _ newforms documentation: ../newforms/81 .. _forms documentation: ../forms/ 82 82 83 83 Creating a ``FormWizard`` class … … 95 95 96 96 * ``request`` -- an HttpRequest_ object 97 * ``form_list`` -- a list of ``django. newforms`` ``Form`` classes97 * ``form_list`` -- a list of ``django.forms`` ``Form`` classes 98 98 99 99 In this simplistic example, rather than perform any database operation, the … … 210 210 return str(step) 211 211 212 .. _form prefix documentation: ../ newforms/#prefixes-for-forms212 .. _form prefix documentation: ../forms/#prefixes-for-forms 213 213 214 214 ``render_hash_failure`` django/trunk/docs/generic_views.txt
r7952 r8020 985 985 </form> 986 986 987 See the ` newforms documentation`_ for more information about using987 See the `forms documentation`_ for more information about using 988 988 ``Form`` objects in templates. 989 989 990 990 .. _authentication system: ../authentication/ 991 991 .. _ModelForm docs: ../newforms/modelforms 992 .. _ newforms documentation: ../newforms/992 .. _forms documentation: ../forms/ 993 993 994 994 ``django.views.generic.create_update.update_object`` django/trunk/docs/index.txt
r7374 r8020 34 34 templates 35 35 templates_python 36 newforms36 forms 37 37 modelforms 38 38 testing django/trunk/docs/localflavor.txt
r7989 r8020 12 12 13 13 Most of the ``localflavor`` add-ons are localized form components deriving from 14 the newforms_ framework -- for example, a ``USStateField`` that knows how to14 the forms_ framework -- for example, a ``USStateField`` that knows how to 15 15 validate U.S. state abbreviations, and a ``FISocialSecurityNumber`` that knows 16 16 how to validate Finnish social security numbers. … … 20 20 French telephone number:: 21 21 22 from django import newforms asforms22 from django import forms 23 23 from django.contrib.localflavor import fr 24 24 … … 59 59 useful code that is not specific to one particular country or culture. 60 60 Currently, it defines date and datetime input fields based on those from 61 newforms_, but with non-US default formats. Here's an example of how to use61 forms_, but with non-US default formats. Here's an example of how to use 62 62 them:: 63 63 64 from django import newforms asforms64 from django import forms 65 65 from django.contrib.localflavor import generic 66 66 … … 93 93 .. _United Kingdom: `United Kingdom (django.contrib.localflavor.uk)`_ 94 94 .. _United States of America: `United States of America (django.contrib.localflavor.us)`_ 95 .. _ newforms: ../newforms/95 .. _forms: ../forms/ 96 96 97 97 Adding flavors django/trunk/docs/model-api.txt
r7977 r8020 717 717 Django comes with quite a few validators. They're in ``django.core.validators``. 718 718 719 .. _validator docs: ../ forms/#validators719 .. _validator docs: ../oldforms/#validators 720 720 721 721 Verbose field names django/trunk/docs/modelforms.txt
r7967 r8020 1 ======================= ===2 Using newforms with models3 ======================= ===1 ======================= 2 Using forms with models 3 ======================= 4 4 5 5 ``ModelForm`` … … 17 17 For example:: 18 18 19 >>> from django. newforms import ModelForm19 >>> from django.forms import ModelForm 20 20 21 21 # Create the form class. … … 87 87 types are special cases: 88 88 89 * ``ForeignKey`` is represented by ``django. newforms.ModelChoiceField``,89 * ``ForeignKey`` is represented by ``django.forms.ModelChoiceField``, 90 90 which is a ``ChoiceField`` whose choices are a model ``QuerySet``. 91 91 92 92 * ``ManyToManyField`` is represented by 93 ``django. newforms.ModelMultipleChoiceField``, which is a93 ``django.forms.ModelMultipleChoiceField``, which is a 94 94 ``MultipleChoiceField`` whose choices are a model ``QuerySet``. 95 95 … … 122 122 123 123 from django.db import models 124 from django. newforms import ModelForm124 from django.forms import ModelForm 125 125 126 126 TITLE_CHOICES = ( … … 241 241 242 242 Other than the ``save()`` and ``save_m2m()`` methods, a ``ModelForm`` 243 works exactly the same way as any other `` newforms`` form. For243 works exactly the same way as any other ``forms`` form. For 244 244 example, the ``is_valid()`` method is used to check for validity, the 245 245 ``is_multipart()`` method is used to determine whether a form requires 246 246 multipart file upload (and hence whether ``request.FILES`` must be 247 passed to the form), etc. See `the standard newforms documentation`_247 passed to the form), etc. See `the standard forms documentation`_ 248 248 for more information. 249 249 250 .. _the standard newforms documentation: ../newforms/250 .. _the standard forms documentation: ../forms/ 251 251 252 252 Using a subset of fields on the form django/trunk/docs/oldforms.txt
r7294 r8020 9 9 replaced in the next Django release. If you're starting from scratch, we 10 10 strongly encourage you not to waste your time learning this. Instead, learn and 11 use the django. newforms system, which we have begun to document in the12 ` newforms documentation`_.11 use the django.forms system, which we have begun to document in the 12 `forms documentation`_. 13 13 14 14 If you have legacy form/manipulator code, read the "Migration plan" section in 15 15 that document to understand how we're making the switch. 16 16 17 .. _ newforms documentation: ../newforms/17 .. _forms documentation: ../forms/ 18 18 19 19 Introduction … … 80 80 from django.shortcuts import render_to_response 81 81 from django.http import Http404, HttpResponse, HttpResponseRedirect 82 from django import forms82 from django import oldforms as forms 83 83 from mysite.myapp.models import Place 84 84 … … 376 376 for a "contact" form on a website:: 377 377 378 from django import forms378 from django import oldforms as forms 379 379 380 380 urgency_choices = ( … … 486 486 487 487 from django.core import validators 488 from django import forms488 from django import oldforms as forms 489 489 490 490 class ContactManipulator(forms.Manipulator): … … 589 589 590 590 from django.core import validators 591 from django import forms591 from django import oldforms as forms 592 592 593 593 power_validator = validators.IsAPowerOf(2) django/trunk/docs/upload_handling.txt
r7970 r8020 18 18 Consider a simple form containing a ``FileField``:: 19 19 20 from django import newforms asforms20 from django import forms 21 21 22 22 class UploadFileForm(forms.Form): … … 49 49 return render_to_response('upload.html', {'form': form}) 50 50 51 .. _binding uploaded files to a form: ../ newforms/#binding-uploaded-files-to-a- form51 .. _binding uploaded files to a form: ../forms/#binding-uploaded-files-to-a- form 52 52 53 53 Notice that we have to pass ``request.FILES`` into the form's constructor; this
