I want to create a list of category with subcategory. Here is the class : class Category(models.Model): parent = models.ForeignKey('self', blank=True, null=True) name = models.CharField(max_length=63) child_list = [] def __unicode__(self): return self.name
I use this to create a tree : def show_categories(): category_list = list(Category.objects.all()) for category in category_list: if category.parent != None: category.parent.child_list.append(category) category_list.remove(category) return {'category_list':category_list} Do you think it is a good idea ? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---