Forms¶
-
class
treebeard.forms.
MoveNodeForm
(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=':', empty_permitted=False, instance=None, **kwargs)¶ Bases:
django.forms.models.ModelForm
Form 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 of
andSibling of
- For unsorted trees:
First child of
,Before
andAfter
- For sorted trees:
Warning
Subclassing
MoveNodeForm
directly 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
Node
that will be handled by the form. - form – The form class that will be used as a base. By
default,
MoveNodeForm
will be used.
Returns: A
MoveNodeForm
subclassFor a full reference of this function, please read
modelform_factory()
Example,
MyNode
is 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