views:

74

answers:

1

Hi all,

I have problem about django template-db query relationship.

For example, I created two tables in db (e.g. Menu & Submenu). Submenu, as you can guess, has a ForeignKey relationship with Menu.

On the template side how can Ido db-query according to this relationship. I want to have a link for Menu such as:

{% for menu in menu_list %}
<li>menu.title</li>
   # And here put each Submenu which has ForeignKey relation with specific Menu
{% endfor %}

Thanks in advance...

+1  A: 

Something like {% for submenu in menu.submenu_set.all %}{# do something #}{% endfor %}.

You should really read the relevant docs before asking a question like this.

ozan
Well, I read it. But couldn't figure out how to edit on views. btw, your suggestion doesn't work. thanks anyway;)
israkir
What does it have to do with views? If that didn't work, I'm guessing you've set a related_name on the foreign key to Menu, in which case you need to use that instead of submenu_set.
ozan