On Jul 31, 12:45 pm, Mirat Bayrak <miratcanbay...@gmail.com> wrote:
> > Do you mean you want the foreign key value to be the 'path' field of
> > the Category model? You could do this, but why would you want to? If
> > you ever want to refer to the category path from an Announce instance,
> > you just do:
> >   announce.category.path
>
> hmm i have to explain more i think lets think that i have a category tree
> like that
>
> All
>    '--- Animals
>     '                     '---Dogs
>     '                     '---Cats
>     '                     '---Fishes
>     '
>     '--- Computers
>                              '--- Laptops
>                              '--- Desktops
>                              '--- Accessories
>
> and that category items has path property like :
>
> All =  "all"
> Animals = "all/animals"
> Dogs = "all/animals/dogs"
> Cats = "all/animals/cats"
> Fishes = "all/animals/fishes"
>
> Now, that is important part,  lets think that i am selected Animals
> category, than announces that is in  Dogs, Cats and Fishes category must be
> shown..
>
> İ tried doing it with loops before but at the result i see that i am making
> too much database queries than i found a method...
>
> later, i found that, if i wrote category path on announces, and write a
> custom manager, i can make a query like
>
> *Announce.objects.GetByCategory("/all/animals")*
> that makes a querty on database
>
> *select * from announces where category startswith 'all/animals' * (i dont
> know sql well ill research later)
>
> than it will result all announces whichs category is Dogs or Cats or Fishes
>
> or *Announce.objects.GetByCategory("/all/")* will return all announces that
> is categorized with Animals or Computers or Laptops or Cats
>
> My english is very bad, i wish i explained well my stiuation. After that
> problem solved i think i can publish my category applicaton.

The question of how to deal with nested categories comes up here a
lot, and I always do the same thing - recommend the MPTT algorithm.
There is an excellent Django implementation, django-mptt, which can be
found at http://code.google.com/p/django-mptt/. This would enable you
to get a category and all its ancestors with a single query.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
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