Django template - How to match model datefield with a date in date generator? -


in models.py task can have multiple employer use manytomanyfield

in views.py got date generator - return range of 2 weeks current day.

so here template

    <table>         <thead>             <tr>                 <th>{% trans 'employer_id' %}</th>                 {% in date_range %}                 <th>{{ }}</th>                 {% endfor %}             </tr>         </thead>         <tbody>         {% employer in employers %}             <tr>                 <td>{{ employer.employer_id }}</td>                 {% t in employer.task_set.all %}                         <td>{{ t }}</td>                     {% empty %}                         <td>0</td>                 {% endfor %}             </tr>         {% endfor %}         </tbody>     </table> 

what need when create task , assign employers, should show me in html table start_date of task of each employers specific days.

so far got codes above: enter image description here

^date of tasks of these employers not matching days in table header.

instead of

            {% t in employer.task_set.all %}                     <td>{{ t }}</td>                 {% empty %}                     <td>0</td>             {% endfor %} 

you need iterate on dates again, since you're not creating <td>'s each date.

{% in date_range %} {% t in employer.task_set.all %} {% if t.start_date == %}     <td>{{ t }}</td> {% else %}     <td>-</td> {% endif %} {% empty %}    <td>0</td> {% endfor %} {% endfor %} 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -