mptt.forms
¶
Form components for working with trees.
-
class
mptt.forms.
TreeNodeChoiceField
(queryset, *args, **kwargs)¶ A ModelChoiceField for tree nodes.
-
class
mptt.forms.
TreeNodeMultipleChoiceField
(queryset, *args, **kwargs)¶ A ModelMultipleChoiceField for tree nodes.
-
class
mptt.forms.
TreeNodePositionField
(*args, **kwargs)¶ A ChoiceField for specifying position relative to another node.
-
DEFAULT_CHOICES
= (('first-child', <django.utils.functional.lazy.<locals>.__proxy__ object at 0x7f6865e0ceb8>), ('last-child', <django.utils.functional.lazy.<locals>.__proxy__ object at 0x7f6865dd42e8>), ('left', <django.utils.functional.lazy.<locals>.__proxy__ object at 0x7f6865dd43c8>), ('right', <django.utils.functional.lazy.<locals>.__proxy__ object at 0x7f6865dd4470>))¶
-
FIRST_CHILD
= 'first-child'¶
-
LAST_CHILD
= 'last-child'¶
-
LEFT
= 'left'¶
-
RIGHT
= 'right'¶
-
-
class
mptt.forms.
MoveNodeForm
(node, *args, **kwargs)¶ A form which allows the user to move a given node from one location in its tree to another, with optional restriction of the nodes which are valid target nodes for the move.
-
base_fields
= OrderedDict([('target', <mptt.forms.TreeNodeChoiceField object at 0x7f6865dd45f8>), ('position', <mptt.forms.TreeNodePositionField object at 0x7f6865dd4668>)])¶
-
declared_fields
= OrderedDict([('target', <mptt.forms.TreeNodeChoiceField object at 0x7f6865dd45f8>), ('position', <mptt.forms.TreeNodePositionField object at 0x7f6865dd4668>)])¶
-
media
¶
-
save
()¶ Attempts to move the node using the selected target and position.
If an invalid move is attempted, the related error message will be added to the form’s non-field errors and the error will be re-raised. Callers should attempt to catch
InvalidNode
to redisplay the form with the error, should it occur.
-