Forms¶
- class treebeard.forms.MoveNodeForm(*args, initial=None, instance=None, **kwargs)¶
Bases:
ModelFormForm to handle moving a node in a tree.
Handles sorted/unsorted trees.
It adds two fields to the form:
- Relative to: The target node where the current node will
be moved to.
- Position: The position relative to the target node that
will be used to move the node. These can be:
For sorted trees:
Child ofandSibling ofFor unsorted trees:
First child of,BeforeandAfter
Warning
Subclassing
MoveNodeFormdirectly is discouraged, since special care is needed to handle excluded fields, and these change depending on the tree type.It is recommended that the
movenodeform_factory()function is used instead.
- treebeard.forms.movenodeform_factory(model, form=<class 'treebeard.forms.MoveNodeForm'>, exclude=None, **kwargs)¶
Dynamically build a MoveNodeForm subclass with the proper Meta.
- Parameters:
model (Node) – The subclass of
Nodethat will be handled by the form.form – The form class that will be used as a base. By default,
MoveNodeFormwill be used.
Accepts all other kwargs that can be passed to Django’s modelform_factory.
- Returns:
A
MoveNodeFormsubclass
For a full reference of this function, please read
modelform_factory()Example,
MyNodeis a subclass oftreebeard.al_tree.AL_Node:MyNodeForm = movenodeform_factory(MyNode)
is equivalent to:
class MyNodeForm(MoveNodeForm): class Meta: model = models.MyNode exclude = ('sib_order', 'parent')