Hello,

I've got a problem with a recursive function:
in my model, I have a class named myClass: each object in my class has
an id, a parentId, and a name.
I want to make a list of all my objects that looks like this:
<ul>
    <li>object1</li>
    <li>object2</li>
    <li>object3
        <ul>
            <li>object4</li>
            <li>object6</li>
        </ul></li>
    <li>object5</li>
    ...
</ul>

So I wrote a function displayListObject():
def displayListObject(parentId, displayString):
    displayString += '<ul>'
    elements = myClass.objects.filter(parentId=parentId)
    for element in elements:
        if  myClass.objects.filter(parentId=page.id):
            displayString += '<li>' + page.id + '</li>'
            displayListObject(page.id, displayString)
        else:
            displayString += '<li>' + page.id + '</li>'
    displayString += '</ul>'
    return displayString

then I call my function: displayListObject('index', '')

It works fine for the first level but doesn't display the others:

<ul>
    <li>object1</li>
    <li>object2</li>
    <li>object3</li>
    <li>object5</li>
    ...
</ul>

Any idea to fix this?

Thank you for your help.








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

Reply via email to