Adding defaults to column headers in django -


i have script imports data in tables other websites. tables between 5 , 15 columns wide , arbitrarily long.

after i've got raw data want opportunity make sure guesses column headers correct. want have @ top list of 15 things column called. way can correct poor decisions made automatic code.

so auto code generates 2 arrays, first of strings:
possible_headers = ["one", "two", "three"...]
second of indexes first array
likely_headers = [2, 0, 5...]
(the columns headers "three" "one" "six")

and use them in template:

{% likely_head in likely_headers %} <th>    <select name="colheader">   {% poss_head in possible_headers %}      {% if forloop.counter0 == likely_headers.forloop.parentloop.counter0 %}       <option value="col:{{forloop.counter0}}" selected>{{poss_head}}</option>     {% else %}       <option value="col:{{forloop.counter0}}">{{poss_head}}</option>     {% endif %}    {% endfor %} </select>  </th>  {% endfor %} 

with idea header selected/default item in select input. problem the:

likely_headers.forloop.parentloop.counter0 

doesn't evaluate. forloop.parentloop.counter0 works correctly apparently cannot used index list.

i'm new django i'm doing wrong, please nice!

i don't see why you're using likely_headers.forloop.parentloop.counter0 when should use forloop.parentloop.counter0 according docs https://docs.djangoproject.com/en/dev/ref/templates/builtins/#for

you may try solving encapsulating counter {% %} tag

{% likely_head in likely_headers %}   {% forloop.counter0 parent_counter %}     {% poss_head in possible_headers %}        {{ parent_counter }}     {% endfor %}   {% endwith %} {% endfor %} 

i haven't checked works sure think should.

also you're trying solve problem should not solved in templates. can try using tags, processing headers in view (using library?) , returning list of headers should rendered.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -