On Thursday, 18 July 2019 15:56:59 UTC+1, Yves de Champlain wrote:
>
> Indeed, it feels like I'm taking things the wrong way, maybe I coded too
> much PHP to be redeemable ...
>
> My main problem might be coming from the fact that I need to parse the
> data to generate my view and can't simply pull the data from the DB.
>
> Here are the models, template and view attached, as well as a screenshot
> of the result.
>
> Please note that as far as the logic of the app is concerned, "Competency"
> means the same as "Skill". I need to fix that dual terminology in the code.
>
> Thanks a lot for your answer.
>
> yves
>
The key is to think about the structure you need for output when building
up your data in the view. In this case, what you want is a simple nested
list which includes *all* the data for each row - including the skill
object. (Also, there's no need to pad your lists with "X" and spaces; use
bools.) In other words, the list looks like:
[
[skill1, [True, False, False...],
[skill2, [True, False, True...].
...
]
So, in the view:
for s in skills:
v_skill = []
valeur = False
for a in achievements:
...
if...
valeur = True
v_skill.append(valeur)
v_table.append(skill, v_skill)
Now in the template you can simply do:
{% for skill, achievements in skills %}
<tr
{% if skill.is_key %}
style="font-weight:bold;"
{% endif %}
>
<td style="text-align:right">{{ skill.code }}</td>
<td>{{ skill.name }}</td>
{% for achievement in achievements %}
<td style="text-align:center">
{{ achievement|yesno:"X, " }}
</td>
{% endfor %}
</tr>
{% endfor %}
--
DR.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/add48121-770b-45e0-8550-a2e5ccbaecf1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.