On Mon, 2008-11-17 at 11:46 +0100, Fabio Natali wrote:
[...]
> The point is, how can I create the root of my tree? Should I add some
> "blank=True, null=True" properties to my Node model? So to have:
> 
> class Node(models.Model):
>     name = models.CharField(max_length=50)
>     parent = models.ForeignKey('self', blank=True, null=True)
> 
> And then consider the "null-parented" node as the root one?

That's the usual method.

> 
> Does my code make any sense? Do you think it will turn out as too slow
> for my hierarchy? Should I better rely on django-treebeard or
> django-mptt?

500 leaves is really nothing for the database. If you want to do
anything with that size tree, you can easily just use a simple nested
hierarchy like this, pull all the rows back into Python and work with
them there. Particularly since you only have three levels in the tree:
queries on name or parent__name or parent__parent__name are as bad as
it's going to get (thereby meaning you can often filter to just the
branches you want).

Things like the modified pre-order tree traversal data structures just
speed up the retrieval so that you don't have to retrieve all the rows
and become useful for large trees, or trees with deep (and unknown)
levels of nesting. So start with something simple, by all means. It's
fun, it's a learning experience, it will probably work very well in
practice. And if you later decide to switch to one of the other
packages, it won't take a lot of changes to move things to the new model
(it will take some changes, but it's not really that difficult).

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to