Django

Code

Changeset 7222

Show
Ignore:
Timestamp:
03/11/08 01:40:50 (9 months ago)
Author:
ubernostrum
Message:

Correct an example in docs/modelforms.txt, and fix some reST formatting

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/modelforms.txt

    r7122 r7222  
    227227    # Create a form instance with POST data. 
    228228    >>> a = Author() 
    229     >>> f = AuthorForm(a, request.POST
     229    >>> f = AuthorForm(request.POST, instance=a
    230230 
    231231    # Create and save the new author instance. There's no need to do anything else. 
     
    239239model fields: 
    240240 
    241     1. Set ``editable=False`` on the model field. As a result, *any* form 
    242        created from the model via ``ModelForm`` will not include that 
    243        field. 
    244  
    245     2. Use the ``fields`` attribute of the ``ModelForm``'s inner ``Meta`` class. 
    246        This attribute, if given, should be a list of field names to include in 
    247        the form. 
    248  
    249     3. Use the ``exclude`` attribute of the ``ModelForm``'s inner ``Meta`` class. 
    250        This attribute, if given, should be a list of field names to exclude 
    251        the form. 
    252  
    253        For example, if you want a form for the ``Author`` model (defined above) 
    254        that includes only the ``name`` and ``title`` fields, you would specify 
    255        ``fields`` or ``exclude`` like this:: 
    256  
    257           class PartialAuthorForm(ModelForm): 
    258               class Meta: 
    259                   model = Author 
    260                   fields = ('name', 'title') 
    261  
    262           class PartialAuthorForm(ModelForm): 
    263               class Meta: 
    264                   model = Author 
    265                   exclude = ('birth_date',) 
    266  
    267         Since the Author model has only 3 fields, 'name', 'title', and 
    268         'birth_date', the forms above will contain exactly the same fields. 
     2411. Set ``editable=False`` on the model field. As a result, *any* form 
     242   created from the model via ``ModelForm`` will not include that 
     243   field. 
     244 
     2452. Use the ``fields`` attribute of the ``ModelForm``'s inner ``Meta`` 
     246   class.  This attribute, if given, should be a list of field names 
     247   to include in the form. 
     248 
     2493. Use the ``exclude`` attribute of the ``ModelForm``'s inner ``Meta`` 
     250   class.  This attribute, if given, should be a list of field names 
     251   to exclude the form. 
     252 
     253For example, if you want a form for the ``Author`` model (defined 
     254above) that includes only the ``name`` and ``title`` fields, you would 
     255specify ``fields`` or ``exclude`` like this:: 
     256 
     257    class PartialAuthorForm(ModelForm): 
     258        class Meta: 
     259            model = Author 
     260            fields = ('name', 'title') 
     261     
     262    class PartialAuthorForm(ModelForm): 
     263        class Meta: 
     264            model = Author 
     265            exclude = ('birth_date',) 
     266 
     267Since the Author model has only 3 fields, 'name', 'title', and 
     268'birth_date', the forms above will contain exactly the same fields. 
    269269 
    270270.. note::