#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 |
-------------------------------------+-------------------------------------
Comment (by tanner):
I have revised my PR to make it fully backwards-compatible.
The field_order attribute/argument is used to rearrange existing fields.
If a key of an existing field is missing in the list, the field is
appended to the fields in the original order.
This way new fields in subclasses are just added (as before) if the
subclass does not override field_order.
If a key in field_order refers to a non-existing field, it is simply
ignored.
This make is possible to remove a field in a subclass by overriding it
with None, without overriding field_order.
Again, this won't break existing subclasses.
If you do not define Form.field_order or set it None, the default order is
kept.
There are now three ways to set the field order:
1. set the class variable as default for all instances
2. pass field_order as argument when instantiating a Form, e.g., when
calling the parent constructor
3. use the order_fields() method to rearrange the field order of an
instance, e.g., in a subclass constructor after some extra fields have
been added.
--
Ticket URL: <https://code.djangoproject.com/ticket/5986#comment:32>
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.fff24afc55d134f4e5bb7d6938e428a1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.