diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-03-15 05:05:26 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-03-15 05:05:26 +0000 |
| commit | 7be4b9a4c005639f03fcd096c3a53fffcb7f210c (patch) | |
| tree | 1719b7912b1ff949b6ac17b08156ceb42071f56d /docs/topics/forms | |
| parent | 24b9c65d3fd9b6fdff9397a03eb4ec9e6f1687c1 (diff) | |
Fixed #8164 -- Fields on a ModelForm are now ordered in the order specified in the fields attribute of the ModelForm's Meta class. Thanks to Alex Gaynor for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10062 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/topics/forms')
| -rw-r--r-- | docs/topics/forms/modelforms.txt | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt index 50beea2d71..f424fb9b60 100644 --- a/docs/topics/forms/modelforms.txt +++ b/docs/topics/forms/modelforms.txt @@ -259,7 +259,8 @@ model fields: 2. Use the ``fields`` attribute of the ``ModelForm``'s inner ``Meta`` class. This attribute, if given, should be a list of field names - to include in the form. + to include in the form. The form will render the fields in the same + order they are specified in the ``fields`` attribute. 3. Use the ``exclude`` attribute of the ``ModelForm``'s inner ``Meta`` class. This attribute, if given, should be a list of field names @@ -336,6 +337,31 @@ parameter when declaring the form field:: ... class Meta: ... model = Article +Changing the order of fields +---------------------------- + +By default, a ``ModelForm`` will render fields in the same order that +they are defined on the model, with ``ManyToManyField``s appearing last. +If you want to change the order in which fields are rendered, you can +use the ``fields`` attribute on the ``Meta`` class. + +The ``fields`` attribute defines the subset of model fields that will be +rendered, and the order in which they will be rendered. For example given this +model:: + + class Book(models.Model): + author = models.ForeignKey(Author) + title = models.CharField(max_length=100) + +the ``author`` field would be rendered first. If we wanted the title field +to be rendered first, we could specify the following ``ModelForm``:: + + >>> class BookForm(ModelForm): + ... class Meta: + ... model = Book + ... fields = ['title', 'author'] + + Overriding the clean() method ----------------------------- |
