Reputation: 65
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??
Upvotes: 3
Views: 1528
Reputation: 2157
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:
Upvotes: 4