Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django-MPTT, how to

Hey, I have just installed the django-mptt lib, but i don't know how to get it to work :(

I have added

from mptt.models import MPTTModel

class Category(MPTTModel):
    slug = models.SlugField(max_length=200, unique=True)
    name = models.CharField(max_length=100)
    parent = models.ForeignKey('self', blank=True, null=True, related_name='child')

It that works fine

-

But when i go to the Django Admin page of my site i got an error:

TemplateDoesNotExist at /admin/search/category/

admin/mptt_change_list.html

like image 896
pkdkk Avatar asked Mar 18 '11 09:03

pkdkk


People also ask

What is MPTT model?

MPTT, or modified preorder tree traversal, is an efficient way to store hierarchical data in a flat structure. It is an alternative to the adjacency list model, which is inefficient.

What is MPTTModel in Django?

django-mptt is a reusable Django app which aims to make it easy for you to use MPTT with your own Django models. It takes care of the details of managing a database table as a tree structure and provides tools for working with trees of model instances.

What is TreeForeignKey?

Set up your model A TreeForeignKey is just a regular ForeignKey that renders form fields differently in the admin and a few other places.


1 Answers

Googling this error message brought me here.

In my case solution was to simply add 'mptt' to INSTALLED_APPS for template loader to find admin/mptt_change_list.html

like image 90
fsw Avatar answered Sep 28 '22 15:09

fsw