Hi everyone,

I'm following this tutorial for recursion in templates:
http://www.undefinedfire.com/lab/recursion-django-templates/
Here is my model:

#models.py
class Category(models.Model):
    parent = models.ForeignKey('self', blank=True, null=True)
    name = models.CharField(max_length=50)
    slug = models.SlugField()

    class Meta:
        verbose_name_plural = 'Categories'

    def __unicode__(self):
        parent = ''
        if self.parent:
            parent = str(self.parent) + ' - '
        return '%s%s' % (parent, self.name)

class CategoryAdmin(admin.ModelAdmin):
    prepopulated_fields = ({ 'slug' : ('name',) })

admin.site.register(Category, CategoryAdmin)


#categories.html
{% load recurse %}
    {% recurse category.category_set.all with categories as category
%}
    <ul>
    {% loop %}
        <li>
            <h{{ level }}>{{ category.name }}</h{{ level }}>
            {% child %}
        </li>
    {% endloop %}
    </ul>
{% endrecurse %}


Let's say I have the following data:
Children
Children > Toys
Children > Clothing

The output I'm seeing is:

Children
    Clothing

When I would expect it to be:
Children
    Clothing
    Toys


Here is my view:
def get_categories(request):
    categories = Category.objects.filter(parent__isnull=True)
    return render_to_response('categories.html', {'categories' :
categories})


If I get my first category root object, and call:
print categories[0].category_set.all()

I get:
[<Toys >, <Clothing >]


Does anyone see what I did wrong?
Kind regards,
Brandon
--~--~---------~--~----~------------~-------~--~----~
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