#5986: Easy way to customize ordering of fields on forms that use inheritance
-------------------------------------+-------------------------------------
     Reporter:  emes                 |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Forms                |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  field order weight   |             Triage Stage:  Accepted
  form newforms                      |      Needs documentation:  0
    Has patch:  1                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Changes (by loic):

 * cc: loic (added)


Comment:

 Replying to [comment:30 carljm]:
 > Hmm, I always thought that relying on ordering of `clean_<field_name>`
 calls was unsupported; a `clean_<field_name>` method should only deal with
 its field and nothing else, if you need to validate multiple fields it
 should be done in `clean`.

 +1, especially now that `add_error()` makes it very easy to do.


 > I think that in most cases forms are better rendered explicitly in the
 template, and that's where field-ordering belongs. But there are use cases
 (more generic applications such as the admin) where that's not practical.
 The fact that we reorder form fields ourselves in Django is a pretty
 strong argument that there should be a public API for it.

 Quoting from the PR regarding `Form.field_order`: "Fields missing in the
 list are removed". I'm worried this adds yet another way of excluding
 fields, `ModelForm` is already pretty confusing with both `fields` and
 `exclude` (and the possible overlap of the two). There is also the
 interaction with `ModelAdmin` that already supports fields ordering
 through `fields` and `fieldsets`.

 Finally I'd like to point out that the proposed API doesn't play well with
 inheritance. We wouldn't be able to use it in `PasswordChangeForm` for
 instance as it would break any subclasses with extra fields.

 Doesn't sorting `self.fields` in `__init__()` achieves the same result
 anyway?

--
Ticket URL: <https://code.djangoproject.com/ticket/5986#comment:31>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/062.faeea28e204378718cd4245ab8b19bdc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to