Derek Stegelman

Django MPTT Custom Managers

The latest version of django-mptt automatically sets your default model manager objects to the built in TreeManager() model manager in django-mptt.

But what if you already have a default custom model manager

Assuming we have the following:

class Area(MPTTModel):
    name = models.CharField(max_length=250)
    slug = models.SlugField(editable=False)
    url = models.URLField(verbose_name='URL', blank=True)

    tree = TreeManager()
    objects = AreaQuerySet.as_manager()

In order to preserve both of your managers, the MPTT TreeManager() need to be placed before the objects manager.

Hopefully this helps someone else having trouble with this issue.