Re: Nested Sets for trees - any models been made before?

2007-03-27 Thread Jonas Maurus

On Mar 27, 2:10 pm, "Nathan Harmston" <[EMAIL PROTECTED]>
wrote:
> HI,
>
> Currently I am trying to store a "tree" in a database and want to use Nested
> Sets in order to do this. I was wondering if this exists within Django atm
> or if there are plans to add it in the future or has someone developed it on
> the side? If the answer to these questions is "NO", is there a reason which
> prevents Nested Sets from being implemented in Django?
>
> I m imagining a model;
>   class Node(models.Model):
>  name = models.TextField()
>  lft = models.IntegerField()
>  rgt = models.IntegerField()
>  objects = NSManager()
>
> and having a manager do all of  the query work...as well as making
> changes to save and delete. Does this seem like the right idea? I m just
> checking before I jump in.
>
> Many Thanks
>
> Nathan

Or you use this

http://code.djangoproject.com/wiki/ModifiedPreorderTreeTraversal

Best regards
Jonas


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Nested Sets for trees - any models been made before?

2007-03-27 Thread Steven Armstrong

Nathan Harmston wrote on 03/27/07 14:10:
> HI,
> 
> Currently I am trying to store a "tree" in a database and want to use Nested
> Sets in order to do this. I was wondering if this exists within Django atm
> or if there are plans to add it in the future or has someone developed it on
> the side? If the answer to these questions is "NO", is there a reason which
> prevents Nested Sets from being implemented in Django?
> 
> I m imagining a model;
>   class Node(models.Model):
>  name = models.TextField()
>  lft = models.IntegerField()
>  rgt = models.IntegerField()
>  objects = NSManager()
> 
> and having a manager do all of  the query work...as well as making
> changes to save and delete. Does this seem like the right idea? I m just
> checking before I jump in.
> 

Maybe you can 'steal' something from here:
http://code.google.com/p/django-discussion/


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Nested Sets for trees - any models been made before?

2007-03-27 Thread Atilla

> Currently I am trying to store a "tree" in a database and want to use Nested
> Sets in order to do this. I was wondering if this exists within Django atm
> or if there are plans to add it in the future or has someone developed it on
> the side? If the answer to these questions is "NO", is there a reason which
> prevents Nested Sets from being implemented in Django?
>
> I m imagining a model;
>   class Node(models.Model):
>  name = models.TextField()
>  lft = models.IntegerField()
>  rgt = models.IntegerField()
>  objects = NSManager()
>
> and having a manager do all of  the query work...as well as making
> changes to save and delete. Does this seem like the right idea? I m just
> checking before I jump in.
>

The best way to manipulate the tree "transparently" would be a custom
manager, that knows how to deal with the necessary updates to the
nested set values, upon insertion, updates, etc. I think it would be
quite nice to manipulate it, using the QuerySet syntax, but do mind
that it could be rather heavy sometimes. If your application would
require frequent inserts/updates, rather than reads, it might become
very slow. Also - if your database is not transaction managed, you can
run into problems and collisions in your tree structure.

Other than that - the Nested Sets idea is very good for storing tree
data in a relational DB, it can offer some considerable gains on
read-heavy systems and it will be very good to see it implemented in
Django.

We're currently trying a similar thing, implementing the tree
management as stored procedures in MySQL, rather than in the
application logic. So far it looks quite promising, since there's no
need to transfer data to the application for this purpose and we're
not doing heavy processing in the procedures.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---