views:

40

answers:

2

I'm trying to create a relationship between "tables" with Appengine/Python. Imagine I have a "table" for items, and a table for colors. I save the color of an item by saving the color key as an atribute of the item.

That's working well, but this particular piece of code is not working:

<select id="colorKey" name="colorKey">
  {% for color in colors %}
    <option value="{{ color.key }}"{% if color.key = item.colorKey %} selected="selected"{% endif %}>
      {{ color.name }} - {{ item.colorKey }} - {{ color.key }}
    </option>
  {% endfor %}
</select>

Since the {{ item.colorKey }} and {{ color.key }} variables are actually the same chain of characters, I only can think in a problem with the types.

{{ item.colorKey }} is a string for sure. But maybe {{ color.key }} is not?

A: 
 {% if color.key = item.colorKey %}

One too few ==?

msw
You might need to use `{% ifequal color.key item.colorKey %}` -- I'm not sure which version of Django ships with App Engine.
Jason Hall
@Jason Hall: Django 0.96.1
mg
It looks like == is new in the latest development version -- http://docs.djangoproject.com/en/dev/ref/templates/builtins/#operator
Jason Hall
I tried == and ifequal and they don't work either :(
ana
BTW, if I try {% if color.name = "Blue" %} then, the if works
ana
but if I try {{ if color.key = "agpjaG9yZXN0b3AlcgwLEgRUZWFtGKuZAgw" }} the if fails, so color.key is not a string... but what type is it?
ana
I just discovered that color.key is an object, not a string. Since I cannot find a way to convert the object in a string, I decided to use the color.name as a reference instead.
ana
A: 

Django doesn't support arbitrary expressions in 'if' tags (or anything else for that matter). You need to use the 'ifequal' tag - see the docs for details.

Nick Johnson