On Tue, Apr 28, 2009 at 3:09 PM, Alex Robbins
<alexander.j.robb...@gmail.com> wrote:
>
> For a real simple solution you might just set up a foreign key field
> that points to the parent of any given category. (If you don't need
> the extra features of those libraries, they might just make things
> more complicated.)
>
> E.g. subcat1-1-1 and subcat1-1-2 are fk'ed to subcat1-1.
> subcat1-1 is fk'ed to cat1
> Anything with a null fk field is a top level category.
>
> I might call the fk field parent, and set the related_name of the
> foreign key to children. Then you could access stuff like this:
>>>>subcat1-1.parent
> <cat1>
>>>>subcat1-1.children.all()
> [ <subcat1-1-1> , <subcat1-1-2>]
>
> Anyway, it works in my head. I haven't actually coded any of it.
> Hope that helps,
> Alex
>

Although this would in fact work, it would be inefficient. mptt adds and
manages additional attributes on your models to allow for efficient retrieval
of all children, all ancestors etc. with a single query instead of executing one
query per parent until you get to the root of the tree. If you want arbitrarily
deeply nested categories, you _really_ want to look into using something
like django-mptt.

Matthias

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to