Setting specific day to print specific message in the django template -


here model:

class sitting(models.model):     sit_date = models.datefield(blank=false)     cut_off_date = models.datefield(null=true, blank=true)     ballot_date = models.datefield(null=true, blank=true)     sess_no = models.foreignkey(session,                                  on_delete=models.cascade)     genre = treeforeignkey('genre', null=true, blank=true, db_index=true) 

here view:

def sitting_list(request):     sitting=sitting.objects.select_related('genre')      return render(         request,         'genre/sitting_list.html',         {'sittings':sitting, },  ) 

here template:

{% block content %} <table>     <tr>   <th>sitting day & date</th>   <th>ministry/division</th>   <th>ballot date</th>      </tr>     {% sitting in sittings %}     <tr>        <td> {{ sitting.sit_date|date:"l, d f, y" }}</td>      {% genre in sitting.genre.get_descendants %}               <td> {{ genre }},</td>          {% endfor %}         <td>(ballot: {{ sitting.ballot_date}})</td>     </tr>         <tr>     </tr>     {% endfor %} </table> {% endblock %} 

it gave following output:

enter image description here

edit :

but want following output:

enter image description here

you can see desired output, ministry's name come when no division exists. numbering , last full stop not coming.

i hope can fixed help.

you need add if statement see if weekday 2 (0-6 mon-sun)

 <td>  {% if sitting.sit_date.weekday == 2 %}       stuff  {% endif %}  {% genre in sitting.genre.get_descendants %}       {{ genre }},  {% endfor %} </td> 

note: moved td formatting style wanted.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -