3

I try for a little while set up django-mptt in my project. I took a sample from tutorial and changed model acordingly which looks like this:

class Genre(MPTTModel):
pk = models.AutoField(primary_key=True)
name = models.CharField(max_length=50, unique=True)
parent = TreeManyToManyField('self', null=True, blank=True, related_name='children')

class MPTTMeta:
    order_insertion_by = ['name']

Unfortunately console prints out something like this:

/srv/tokedu/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/models/base.pyc in _set_pk_val(self, value)
    426 
    427     def _set_pk_val(self, value):
--> 428         return setattr(self, self._meta.pk.attname, value)
    429 
    430     pk = property(_get_pk_val, _set_pk_val)
/srv/tokedu/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/models/base.pyc in _set_pk_val(self, value)
    426 
    427     def _set_pk_val(self, value):
--> 428         return setattr(self, self._meta.pk.attname, value)
    429 
    430     pk = property(_get_pk_val, _set_pk_val)
RuntimeError: maximum recursion depth exceeded

I think django-mptt just not support TreeManyToManyField. Anyone had the same problem??

delete
  • 55
  • 7

1 Answers1

3

Nodes can't have more than one parent. That fundamentally changes your data structure - it's no longer a tree, it's an arbitrary graph.

django-mptt only handles trees. If you have a large graph database, you've got a very different problem. You might want to look into using a graph database rather than an RDBMS.

AFAIK there's no django apps which make graph structures easy, but then again I've never really needed to :)

Useful links:

Shog9
  • 156,901
  • 35
  • 231
  • 235
craigds
  • 2,072
  • 14
  • 25
  • Thanks! I found good graph database Neo4j and it has it's own integration in Djano (check neo4django package [link](https://github.com/scholrly/neo4django) - unfortunately under construction - it crashes after second node creation :)). I'l try to play with it a little bit more though! – delete Mar 25 '12 at 22:19