Django

Code

Ticket #8164: fieldorderdocs.diff

File fieldorderdocs.diff, 1.4 kB (added by kire, 2 years ago)

Documentation

  • docs/modelforms.txt

    old new  
    262262 
    2632632. Use the ``fields`` attribute of the ``ModelForm``'s inner ``Meta`` 
    264264   class.  This attribute, if given, should be a list of field names 
    265    to include in the form. 
     265   to include in the form. Note that this attribute also changes the 
     266   order in which fields are displayed in the resulting form (see  
     267   below). 
    266268 
    2672693. Use the ``exclude`` attribute of the ``ModelForm``'s inner ``Meta`` 
    268270   class.  This attribute, if given, should be a list of field names 
     
    339341   ...     class Meta: 
    340342   ...         model = Article 
    341343 
     344Customizing field order 
     345------------------------------- 
     346 
     347By default django will show the model's fields first, followed by any form- 
     348specific fields. When you define the  ``field`` attribute of the  
     349``ModelForm``'s inner ``Meta`` class, that order will be used:: 
     350    
     351   >>> Class CustomAuthor(ModelForm): 
     352   ...     pseudonym = CharField() 
     353   ...      
     354   ...     class Meta: 
     355   ...         model = Author 
     356   ...         fields = ('name', 'pseudonym', 'birth_date') 
     357 
     358This will render a form with the pseudonym field in between name and birth_date. 
     359You can declare model fields, new fields and overridden fields in the ``fields`` 
     360attribute. 
     361 
     362 
    342363Form inheritance 
    343364---------------- 
    344365