django - Maximum Recursion Depth? How to prevent? -


i'm trying recurse list.

but if have 1 task under task runs error maximum recursion depth? why?

task_recurse.html

{% if items %}   <ul>     {% task in items %}       <li>         {{ task.name }}          {% items=task.subtask.all template_name="task_recurse.html" %}             {% include template_name %}         {% endwith %}         </li>     {% endfor %}   </ul> {% endif %} 

task.html

{% include "task_recurse.html" items=items %} 

task model

  class task(models.model):    name = models.charfield(max_length=100)    notes = models.textfield()    created = models.datetimefield()    created_by = models.foreignkey(user)    subtask = models.manytomanyfield('self') 

it gives me error on view? problem?

def tasks(request):   items = task.objects.all()  return render(request, 'tasks.html', {'items': items})  

so 2 questions really:

1) why return maximum recursion depth when have 2 tasks 1 task subtask ?

2) how can prevent infinite recursion ?

as defined subtask = models.manytomanyfield('self') taska has taskb subtask , taskb has taska subtask can see when comment out include template in task_recurse.html

output:

task b    task task    task b 

you have created graph relation instead of tree. change manytomany relationship foreignkey , desired results:

subtask = models.foreignkey('self',null=true, blank=true) 

i included null=true, blank=true first element (tree head) has no subtask


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -