On Tue, Jun 10, 2008 at 5:33 PM, John Teague <[EMAIL PROTECTED]> wrote:
> > First the particulars: > Django svn rev 7610, > Apache 2.2.8, > mod_python 3.3.1, > Python/2.5.2 > > I have a template that uses django_template_utils (http:// > code.google.com/p/django-template-utils/) to retrieve objects. The > following is the relevant markup/code: > ---------- > {% load generic_content %} > {% get_latest_objects dispatcher.dispatchlog 100 as log_item %} > {% for log_item in log_item %} > <tr id="{{ log_item.id }}"> > <td>{% ifequal log_item.id 1 %}<div class="urg3">{{ log_item.id }}{% > endifequal %}</td> > <td>{% ifequal log_item.priority_level 'High' %}<div > class="urg3">{{ log_item.priority_level }}</div>{% endifequal %}</td> > </tr> > {% endfor %} > ---------- > > As you can see, what I want to do is to set the appropriate extra div > and class based on the comparison of the hard-coded string. In the > first use of the ifequal on the 'id' field. I get the expected result. > The integer 1 matches the returned value and renders the the extra > div. > > However, in the second example 'priority_level' field, the returned > value is 'High' which should match the comparison to the hard-coded > string 'High'. I have verified that this is a match. However, the > ifequal fails silently. As near as I can tell, the only difference > between the two fields is that the priority_value field is a > foreignkey. Obviously, the value of the foreign key is, in this case, > a pk integer, but the name is returned in what should be just a string > __str__. > > Am I missing something simple here? Any help would be very much > appreciated. > (You mean priority_level is a ForeignKey, right, not priority_value?) The variable resolution done by ifequal isn't automatically going to call str() on the variable, so if you want to compare what the __str__ method returns against a string, then you need to include that in the comparison: {% ifequal log_item.priority_level.__str__ 'High' %} Karen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---