Forms¶
-
class
treebeard.forms.MoveNodeForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False, instance=None)¶ Bases:
django.forms.models.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 of - For unsorted trees:
First child of,BeforeandAfter
- For sorted trees:
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'>, fields=None, exclude=None, formfield_callback=None, widgets=None)¶ 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.
Returns: A
MoveNodeFormsubclassFor 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')
- model (Node) – The subclass of