Django if statement with foreign key

James Garner

Cut it short I have a model called Page and a field called "parent" that links to itself, I want to write if the nav.parent has a parent called home then do this but for some reason it doesn't work.

{% if nav.parent == "home" %}

Thanks in advanced!

Daniel Roseman

The problem is of course that Django doesn't know which field to use when comparing, unless you tell it. Since "home" is in the title field, you need to actually specify that field:

{% if nav.parent.title == "home" %}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related