Django templates - how to strictly check for equality of a string

734 Views Asked by At

I struggling to solve the following:

I am customizing django tabular inline template which contains several fields.

I have a condition

{% if field.field.name == 'productid' %} ... {% endif %}

However there are two fields that have the ... condition applied which is "productid" and "distributionid price productid" - both contain the productid word. However, I want only the former to have it. How can I make this condition more strict?

Any help will be much appreciated.

EDIT: html file:

        {% if field.field.name == 'productid' %}
                <input type="text" name="PN" id="PN" placeholder="PN:"/>
        {% endif %}
        {% if field.field.name != 'productid' %}
            <td class="field-{{ field.field.name }}"
               data-id="{{ field.field.id }}" data-type="id">

          {% if field.is_readonly %}
              <p>{{ field.contents }}</p>
          {% else %}
              {{ field.field.errors.as_ul }}
              {{ field.field }}
          {% endif %}

(rerults in result)

1

There are 1 best solutions below

0
On BEST ANSWER

Your if condition is outside the field td. Just put it with field.field tag

                  {% if field.is_readonly or not field.field.is_hidden %}
                  <td{% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
                  {% if field.is_readonly %}
                      <p>{{ field.contents }}</p>
                  {% else %}
                      {{ field.field.errors.as_ul }}
                      {{ field.field }}
                      {% if field.field.name == 'productid' %}
                            <input type="text" name="PN" id="PN" placeholder="PN:"/>
                      {% endif %}
                  {% endif %}
                  </td>
                  {% endif %}