mptt.fields

Model fields for working with trees.

class mptt.fields.TreeForeignKey(to, on_delete, related_name=None, related_query_name=None, limit_choices_to=None, parent_link=False, to_field=None, db_constraint=True, **kwargs)

Extends the foreign key, but uses mptt’s TreeNodeChoiceField as the default form field.

This is useful if you are creating models that need automatically generated ModelForms to use the correct widgets.

formfield(**kwargs)

Use MPTT’s TreeNodeChoiceField

class mptt.fields.TreeOneToOneField(to, on_delete, to_field=None, **kwargs)
formfield(**kwargs)

Pass limit_choices_to to the field being constructed.

Only passes it if there is a type that supports related fields. This is a similar strategy used to pass the queryset to the field being constructed.

class mptt.fields.TreeManyToManyField(to, related_name=None, related_query_name=None, limit_choices_to=None, symmetrical=None, through=None, through_fields=None, db_constraint=True, db_table=None, swappable=True, **kwargs)
formfield(**kwargs)

Pass limit_choices_to to the field being constructed.

Only passes it if there is a type that supports related fields. This is a similar strategy used to pass the queryset to the field being constructed.