I have a table made of of several records, with the rows having different number of records per row. What I'd like to have is for the rows with less records, I want to have them being equal in length to the longest row. Currently what I have comes out like below:
I've done this using this bit of code:
<table>
{% for week in month_days %}
{% for day, entries, weekday in week %}
<tr class="{% cycle 'row1' 'row2' %}">
{% if day != 0 %}
<td>{{ weekday }}</td>
<td>{{ day }}</td>
{% if entries %}
{% for entry in entries %}
<td>{{ entry.start_time|time:"h:i a" }}</td>
<td>{{ entry.end_time|time:"h:i a" }}</td>
<td>{{ entry.hours }}</td>
<td>Break</td>
{% endfor %}
{% endif %}
{% endif %}
</tr>
<!--- Insert blank row after each Sunday -->
{% if weekday == "Sunday" %}
<tr class="week-end">
<td colspan="{{ days_month.count }}"> </td>
</tr>
{% endif %}
{% endfor %}
{% endfor %}
</table>
From the above photo, as an example, I want, on the entry for Monday 16th, to have the blue space filled in with blank cells.
Try this:
{% if entries %}
{% for entry in entries %}
<td>{{ entry.start_time|time:"h:i a" }}</td>
<td>{{ entry.end_time|time:"h:i a" }}</td>
<td>{{ entry.hours }}</td>
<td>Break</td>
{% endfor %}
{% else %}
<td> </td>
<td> </td>
<td> </td>
{% endif %}
Related
would like to change text color of win and loss to red and green
not sure how to accomplish this
<tbody>
{% for bet in bets %}
<tr>
<td>{{ bet.name }}</td>
<td>{{ bet.bet_summary }}</td>
<td>{{ bet.bet_content }}</td>
<td>{{ bet.game_start_date_and_time }}</td>
<td>{{ bet.rating | raw }}</td>
<td>{% if bet.bet_outcome is same as(0) %}
LOSS
{% elseif bet.bet_outcome is same as(1) %}
WIN
{% elseif bet.bet_outcome is same as(2) %}
PUSH
{% elseif bet.bet_outcome is same as(3) %}
CANCELLED
{% else %}
TBA
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
I am trying to create a table with HTML tags but I am stuck with it.
I've tried to play with {% for i in list %}, but I couldn't find a solution.
list = {'ticker': tickers, 'price': prices}
<tbody>
<tr>
{% for i in price %}
<td>{{ i }}</td>
{% endfor %}
{% for i in ticker %}
<td>{{ i }}</td>
{% endfor %}
</tr>
<tr>
</tr>
</tbody>
I would see two columns one close to another, but I don't see any columns now.
try this
<tbody>
{% for i in list %}
<tr>
<td>{{ i.ticker }}</td>
<td>{{ i.price }}</td>
</tr>
{% endfor %}
</tbody>
for more details refer this
hope it helps
I have a list of list like :
[[elem0, elem1, elem2], [elem3, elem4, elem5], [elem6, elem7, elem8], ...]
I wrote the follow template file :
{% for result in results %}
<tr>
<td>result[0]</td>
<td>result[1]</td>
<td>result[2]</td>
</tr>
{% endfor %}
But it didn't work, What i can think is use nested for. Is there another method to access the element in the list in jinja?
You still need to output the loop variables inside braces.
{% for result in results %}
<tr>
<td>{{ result[0] }}</td>
<td>{{ result[1] }}</td>
<td>{{ result[2] }}</td>
</tr>
{% endfor %}
Also, consider a nested for loop:
{% for result in results %}
<tr>
{% for elem in result %}
<td>{{elem}}</td>
{% endfor %}
</tr>
{% endfor %}
I will try to explain myself as best I can:
I am developing a kind of social network, in wich there are people registered and you can add as your friends. Once you have friends adds to your list of friends, when you want to list all the users that are in the social network (with Jinja2), I would like to inform somehow which of those users are your friends, for example:
{% for user in user_list %}
<tr>
<td> {{ user.username }}</td>
</tr>
{% endfor %}
The code above will show all the usernames registered on the website. And the code below the usernames of my friends:
{% for friend in friends_list %}
<tr>
<td> {{ friend.username }}</td>
</tr>
{% endfor %}
How can I do something like:
{% for user in user_list %}
<tr>
{% if user "is inside" friends_list %}
<td> {{ user.username }}</td>
<td> FRIEND</td>
{% else %}
<td> {{ user.username }}</td>
<td>NO FRIEND</td>
{% endif %}
</tr>
{% endfor %}
I went through the Jijna2 documentation and I didn't find anything usefull...
Thanks verymuch!
Why not use user in friends_list ...
{% for user in user_list %}
<tr>
{% if user in friends_list %}
<td> {{ user.username }}</td>
<td> FRIEND</td>
{% else %}
<td> {{ user.username }}</td>
<td>NO FRIEND</td>
{% endif %}
</tr>
{% endfor %}
Hope this helps!
I'm creating an e-commerce website and I wanted to build a page where I could view a list of all the orders created.
If the order contains just 1 type of item, the format works correctly, but i can't think of a way to construct the table when there are multiple types of items ordered.
This is how it looks like when there are 2 items ordered (last entry):
I want the "Queso Burrito" to be right under "steak and egg burrito" for #18.
This is my code:
<table>
<tr>
<td>#</td>
<td>Name</td>
<td>Email</td>
<td>Phone</td>
<td>Order</td>
<td>Order Quantity</td>
<td>Delivered</td>
</tr>
{% for ord in orders %}
<tr>
<td>{{ord.pk}}</td>
<td>{{ord.user.first_name}}</td>
<td>{{ord.user.email}}</td>
<td>{{ord.user.get_profile.phone}}</td>
{% for food in ord.orderitem_set.all %}
<td>{{food.name}}</td>
<td>{{food.quantity}}</td>
{% endfor %}
<td>x</td>
</tr>
{% endfor %}
</table>
With multiple items, you typically see tables with order data repeated for each line item.
{% for order in orders %}
{% for orderitem in order.items %}
<td>{{order.id}}</td><td>...</td>
{% endfor %}
{% endfor %}
If you want exactly the formatting you described, you could check if the inner loop is past its first item and hide the fields you don't want repeated.
<table>
{% for ord in orders %}
{% for item in ord.orderitem_set.all %}
<tr>
{% if forloop.counter == 1 %}
<td>{{ord.pk}}</td>
<td>{{ord.user.first_name}}</td>
<td>{{ord.user.email}}</td>
<td>{{ord.user.get_profile.phone}}</td>
{% else %}
<td colspan="4"></td>
{% endif %}
<td>{{item.name}}</td>
<td>{{item.quantity}}</td>
<td>{% if forloop.counter == 1 %}x{% endif %}</td>
</tr>
{% endfor %}
{% endfor %}
</table>