I'm having some trouble joining or correctly formatting my template... I'm new and have taught myself alot so far, but I'm having trouble with queries and for statements.
What I have so far is:
Output
June 13, 2016 June 14, 2016
Item Amount Amount
Cars 10800.00
Tires 156400.00
10200.00
156001.00
About
What I want is to get the "second" output under the next amount column. Am I not making the correct queries?
template/Index
<body>
{% if data %}
{% if date %}
{{ date.date }}
{% endif %}
<table>
<tr>
<th>List Item</th>
<th>Amount</th>
<th>Amount</th>
</tr>
<tr>
{% for firstdata in data %}
<td>{{ firstdata.item }}</td>
<td>{{ firstdata.amount }}</td>
</tr>
{% endfor %}
{% for firstdata in data1 %}
<td>{{ firstdata.amount }}</td>
</tr>
{% endfor %}
{% else %}
<strong>There are no categories present.</strong>
{% endif %}
</table>
<a href="/rango/about/">About</a>
</body>
views.py
def index(request):
context_dict = {}
statement = "Sales"
try:
now = datetime.date.today()
recentdate = StatementData.objects.order_by('date').distinct('date').filter(date__lte=now).reverse()[0]
context_dict['date'] = recentdate
first_statement = StatementData.objects.order_by('-id').filter(date=recentdate.date).values('item', 'amount')
context_dict['data'] = first_statement
now = datetime.date.today()
recentdate1 = StatementData.objects.order_by('date').distinct('date').filter(cik=cik, date__lte=now).reverse()[1]
#context_dict['date1'] = recentdate1
second_statement = StatementData.objects.order_by('-id').filter(date=recentdate1.date).values('amount')
#second_statement = StatementData.objects.order_by('-id').filter(date=recentdate1.date).values('id')
context_dict['data1'] = second_statement
#two_dates = first_statement | second_statement
#context_dict['data1'] = two_dates
except StatementData.DoesNotExist:
# We get here if we didn't find the specified category.
# Don't do anything - the template displays the "no category" message for us.
pass
# Go render the response and return it to the client.
return render(request, 'profit/index.html', context_dict)
Aucun commentaire:
Enregistrer un commentaire